Sum Consecutive Identical Digits
Updated
Problem statement
Given a string digits consisting only of decimal digits, repeatedly combine adjacent identical digits until no such pair remains.
At each step, choose the leftmost pair of identical adjacent digits. Replace that pair with the decimal representation of the sum of their numeric values, then restart the search from the beginning of the updated string.
For digits = "99823":
- The leftmost pair
99becomes18, producing18823. - The leftmost pair
88becomes16, producing11623. - The leftmost pair
11becomes2, producing2623.
No identical adjacent digits remain, so return "2623".
Complete sumConsecutiveIdenticalDigits, which takes digits and returns the final string.
Function
sumConsecutiveIdenticalDigits(digits: String) → StringExamples
Example 1
digits = "99823"return = "2623"- 99 becomes 18 → 18823
- 88 becomes 16 → 11623
- 11 becomes 2 → 2623
Now there are no more consecutive identical digits, so output the final result: 2623.
More PayPay interview questions
Similar questions at other companies
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Filter Isolated Interior Signal BitsSEDEMAC · OA
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Telephone Keypad String EncodingEpic · OAEpic interview questions
- Count Invalid Log GroupsIBM · OAIBM interview questions
- Count Case-Insensitive TripletsTikTok · OATikTok interview questions
- Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions