Problem · String
Repeated Grouped Digit Sum
Learn this problemProblem statement
You are given a non-negative integer number represented as a string of digits and a positive integer k. Repeatedly perform the following algorithm:
- If the length of
numberis at mostk, stop. - Split
numberfrom left to right into groups ofkdigits. The final group may contain fewer thankdigits. - Compute the sum of the digits in each group and concatenate the decimal representations of those sums in the same order.
- Replace
numberwith the concatenated result and return to step 1.
Return the resulting string number when the algorithm stops. It is guaranteed that the algorithm eventually terminates.
A solution with time complexity no worse than O(number.length * NUMBER_OF_STEPS) fits within the execution time limit.
Function
repeatedGroupedDigitSum(number: String, k: int) → StringExamples
Example 1
number = "11111222322"k = 3return = "144"- Split
11111222322into111,112,223, and22. Their digit sums are3,4,7, and4, producing3474. - Split
3474into347and4. Their digit sums are14and4, producing144. - The length of
144is3, which is at mostk, so return144.
More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026