Reduce a Number to One Digit
Updated
Problem statement
Given a non-negative integer num, repeatedly replace it with the sum of its decimal digits until only one digit remains.
Return that final single digit. If num is already a single digit, return it unchanged.
Function
reduceToOneDigit(num: int) → intExamples
Example 1
num = 38return = 2The first digit sum is 3 + 8 = 11. Summing again gives 1 + 1 = 2.
Example 2
num = 0return = 00 is already a single digit, so it is returned unchanged.
Example 3
num = 9998return = 8The reductions are 9 + 9 + 9 + 8 = 35 and then 3 + 5 = 8.
Constraints
0 <= num <= 10^9.
More Accenture interview questions
- Nearest Composite NumberOA · Seen Sep 2026
- Minimum Password IncrementsOA · Seen Sep 2026
- Candy DistributionOA · Seen Sep 2026
- Customers Who Never OrderedOA · Seen Sep 2026
- Economical TripOA · Seen Sep 2026
- Coin ChangeOA · Seen Sep 2026
- Validate Email AddressOA · Seen Sep 2026
- Closest Rhyming WordOA · Seen Aug 2026
- Array Leader ElementsOA · Seen Nov 2025
- Alternating Index Square SumONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Distinct Chapters Missed During a Cyclic AbsenceVisa · OAVisa interview questions
- Count Palindromic Base RepresentationsSEDEMAC · OA
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Calculate the Half SpreadMillennium · OAMillennium interview questions
- Plus Mult ArrayIBM · OAIBM interview questions
- Product Minus Sum of DigitsTikTok · OATikTok interview questions
- Progressive Tax CalculatorInteractive Brokers · OA