Tap here to switch tabs
Problem
Submissions

Problem: Calculate Digit Sum of a String

med
30 min
Try to solve the Calculate Digit Sum of a String problem.

Statement

You are given a string s consisting of digits and an integer k.

A round can be completed if the length of s is greater than k. In a single round, perform the following consecutive actions:

  1. Divide s into consecutive groups of size k such that the first k characters belong to the first group, the next k characters belong to the second group, and so on. The final group may contain fewer than k characters.

  2. Replace each group with the string representation of the sum of its digits.

  3. Concatenate all resulting strings in their original order to form the updated string s.

Repeat this process until the length of s is less than or equal to k.

Return s after completing all possible rounds.

Constraints:

  • 1≤1 \leq s.length ≤100\leq 100

  • 2≤2 \leq k ≤100\leq 100

  • s consists of digits only.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Calculate Digit Sum of a String

med
30 min
Try to solve the Calculate Digit Sum of a String problem.

Statement

You are given a string s consisting of digits and an integer k.

A round can be completed if the length of s is greater than k. In a single round, perform the following consecutive actions:

  1. Divide s into consecutive groups of size k such that the first k characters belong to the first group, the next k characters belong to the second group, and so on. The final group may contain fewer than k characters.

  2. Replace each group with the string representation of the sum of its digits.

  3. Concatenate all resulting strings in their original order to form the updated string s.

Repeat this process until the length of s is less than or equal to k.

Return s after completing all possible rounds.

Constraints:

  • 1≤1 \leq s.length ≤100\leq 100

  • 2≤2 \leq k ≤100\leq 100

  • s consists of digits only.