Problem · Math

Sum Digits Until One

Learn this problem
EasyCapital One logoCapital OneFULLTIMEOA

Problem statement

Given a list of strings representing numbers, repeatedly sum the digits of each number until it becomes a single-digit value. Return the mode of the resulting single-digit values.

The input is guaranteed to have a unique mode after all numbers are reduced to one digit.

For example, ["1234", "24", "33"] becomes ["10", "6", "6"], then ["1", "6", "6"], so the result is 6.

Complete sumDigitsUntilOne, which receives List<String> numbers and returns the unique modal single-digit value as an int.

Function

sumDigitsUntilOne(numbers: List<String>) → int

Examples

Example 1

numbers = ["1234", "24", "33"]return = 6

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.

More Capital One problems

drafts saved locally
public int sumDigitsUntilOne(List<String> numbers) {
  // write your code here
}
numbers["1234", "24", "33"]
expected6
checking account