BackeasyMath

Frequent Digit Identifier Solution

Problem Statement

Given an array of integers, determine the digit that appears more than n/2 times where n is the length of the array.

Example 1
Input
[3, 3, 8, 3, 3, 3, 9, 3, 3]
Output
3

Explanation: The digit 3 appears 7 times which is more than n/2 (9/2 = 4.5) times.

Example 2
Input
[1, 2, 5, 2, 2, 5, 5, 5, 5]
Output
5

Explanation: The digit 5 appears 5 times which is more than n/2 (9/2 = 4.5) times.

Example 3
Input
[4, 4, 4, 4, 4, 4, 4]
Output
4

Explanation: The digit 4 appears 7 times which is more than n/2 (7/2 = 3.5) times.

Constraints

  • 1 <= n <= 1000
  • The array will always have a digit that appears more than n/2 times
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free