FastPrepFastPrep
Problem Brief

Sum Digits Until One

FULLTIMEOA

Given a list, for each element in the list, repeatedly sum the digits until it becomes a single-digit number. Then return the mode of the resulting numbers.

For example: ['1234', '24', '33']['10', '6', '6']['1', '6', '6'] So the result is 6.

Function Description

Complete the function sumDigitsUntilOne in the editor.

sumDigitsUntilOne has the following parameter:

  1. List numbers: a list of strings representing numbers

Returns

int: the mode of the single-digit numbers obtained by repeatedly summing the digits

1Example 1

Input
numbers = ["1234", "24", "33"]
Output
6
Explanation

The process of summing the digits repeatedly until a single-digit number is obtained is as follows:

  • 1234 → 1+2+3+4 = 10 → 1+0 = 1
  • 24 → 2+4 = 6
  • 33 → 3+3 = 6

The resulting single-digit numbers are 1, 6, and 6. The mode of these numbers is 6.

public int sumDigitsUntilOne(List<String> numbers) {
  // write your code here
}
Input

numbers

["1234", "24", "33"]

Output

6

Sign in to submit your solution.