FastPrepMaximum Digital Root

Maximum Digital Root

Visa logoVisa● EasyFULLTIMEOA
Learn

Problem statement

You are given an integer array values.

For each value, repeatedly replace it with the sum of its decimal digits until only one digit remains. This final digit is the value's digital root.

Return the maximum digital root among all values in the array.

Function

maxDigitalRoot(values: int[]) → int

Examples

Example 1

values = [123,456,789,101]return = 6

The repeated digit sums are 123 -> 6, 456 -> 15 -> 6, 789 -> 24 -> 6, and 101 -> 2. The maximum is 6.

Example 2

values = [999,19,0]return = 9

999 has digital root 9, 19 has digital root 1, and 0 remains 0.

Constraints

  • 1 <= values.length <= 105
  • 0 <= values[i] <= 109

More Visa problems

See Visa hiring insights
public int maxDigitalRoot(int[] values) {
    // Write your code here.
}
values[123,456,789,101]
expected6
Checking account…