Repeatedly Add Consecutive Equal Digits
Learn this problemProblem statement
See the Image Source section at the very bottom of the page for the original problem statement 🐼
Imagine you're given a string made entirely of digits, and your goal is to transform it by repeatedly applying a special operation whenever there are consecutive identical digits. Here's how it works: if a number has repeated digits, you replace each group of consecutive digits with their sum. For example, the number "999433" would become "2746" because 9 + 9 + 9 equals 27, and 3 + 3 equals 6. You keep doing this until there are no consecutive digits left. For instance, "44488366664" would first transform to "12163244." Keep applying this process until the string no longer has any repeating digits, and that's your final result. The challenge here is to find an approach that gets this done efficiently, though it doesn't need to be the most optimal one.
🐰 Appreciation to Charlotte baby 🐰
Function
repeatedlyAddConsecutiveEqualDigits(number: String) → StringExamples
Example 1
number = "999433"return = "2746"Example 2
number = "44488366664"return = "12163244"Example 3
number = "66644319333"return = "26328"Example 4
number = "0044886"return = "084"number = "08166". Then it sequentially becomes 08112
P.S. The explanation isn't complete. I'll add more once I find more reliable source :)Constraints
More Uber problems
- Minimum Refueling StopsONSITE INTERVIEW · Seen Jul 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026