n. While it has more than one digit, replace it with the sum of its digits. Return the single digit you end up with.
Can you do it in O(1), with no loops or recursion?n=4975 → 7
4 + 9 + 7 + 5 = 25, then 2 + 5 = 7, a single digit.
n=6 → 6
The number already has one digit, so there is nothing to add.
n=99 → 9
9 + 9 = 18, then 1 + 8 = 9.
n ≤ 2³¹ − 1n=4975
7
Run checks the first 3 tests in your browser. Submit checks all 40 tests on the server, hidden ones included.