Problem · Array

Most Frequent Reduced Digit

Learn this problem
EasyMeta logoMetaINTERNOA
See Meta hiring insights

Problem statement

You are working with data collected from various sensors. Given an array of non-negative integers readings, repeatedly replace each value with the sum of its decimal digits until every value is a single digit.

Return the most frequent digit in the final transformed array. If several digits have the same highest frequency, return the highest such digit.

A solution with time complexity no worse than O(readings.length^2) will fit within the execution time limit.

Function

solution(readings: int[]) → int

Examples

Example 1

readings = [123,456,789,101]return = 6
  • 123 becomes 1 + 2 + 3 = 6.
  • 456 becomes 4 + 5 + 6 = 15, then 1 + 5 = 6.
  • 789 becomes 7 + 8 + 9 = 24, then 2 + 4 = 6.
  • 101 becomes 1 + 0 + 1 = 2.

The final array is [6,6,6,2], so the most frequent digit is 6.

Example 2

readings = [6]return = 6

The reading 6 is already a single digit, so the final array remains [6] and the result is 6.

Constraints

  • Every value in readings is a non-negative integer.

More Meta problems

drafts saved locally
public int solution(int[] readings) {
    // write your code here
}
readings[123,456,789,101]
expected6
checking account