Add Digits Until One Remains
Updated
Problem statement
Given a non-negative integer n, add up its decimal digits. If the result has more than one digit, add up its digits again. Repeat until one digit is left, and return that digit.
If n already has one digit (including 0), return it unchanged.
Function
addDigits(n: int) → intExamples
Example 1
n = 4728return = 34 + 7 + 2 + 8 = 21, which has two digits, so add again: 2 + 1 = 3.
Example 2
n = 81return = 98 + 1 = 9, already one digit. A multiple of 9 ends at 9, not at 0.
Example 3
n = 5return = 55 already has one digit, so it is the answer.
Constraints
0 <= n <= 2^31 - 1
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Smaller Clock Hand AngleAmazon · PHONE SCREEN
- Count Months Starting on SundayWalmart · PHONE SCREENWalmart interview questions