Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Most Frequent Digit

Basic Acceptance 84.69% Points 10.00

You are given a non-negative integer n. Your task is to return the digit that appears most frequently in the number.

If multiple digits have the same highest frequency, return the smallest digit among them.

Examples
Example 1

Input: n = 1122234
Output: 2
Explanation: The digit 2 appears three times, more frequently than any other digit.

Example 2

Input: n = 1213141
Output: 1
Explanation: The digit 1 appears four times, making it the most frequent digit.

Example 3

Input: n = 1234
Output: 1
Explanation: All digits appear once, so the smallest digit, 1, is returned.

Constraints
  • 0 = n = 10¹8
Companies
Amazon Visa Coinbase
Topics
Data Structures Basics Searching Algorithms
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions