Skip to content

Practice Calculate Digit Sum of a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2243
LeetCode Problem

Calculate Digit Sum of a String

Problem Statement

While s contains more than k digits, split it into consecutive groups of k digits, allowing a shorter final group. Replace each group with the decimal representation of the sum of its digits, then concatenate these representations in order to form the next s. Return s when its length is at most k.

Source: Calculate Digit Sum of a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "11111222223", k = 3
Output
"135"

# Example 2

Input
s = "00000000", k = 3
Output
"000"

Constraints

1 <= s.length <= 100
2 <= k <= 100
s consists of digits only.

Related LeetCode Problems

Practice more problems similar to Calculate Digit Sum of a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.