Menu

2243. Calculate Digit Sum of a String
πŸ“°

2243. Calculate Digit Sum of a String

DEV Community: phpΒ·MD ARIFUL HAQUEΒ·2 days ago
#mtynOeLu
#devto#dev#string#group#round
Reading 0:00
15s threshold

2243. Calculate Digit Sum of a String

Difficulty: Easy

Topics: Mid Level , String , Simulation , Weekly Contest 289

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 one round, do the following:

Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k .

Replace each group of s with a string representing the sum of all its digits. For example, "346" is replaced with "13" because 3 + 4 + 6 = 13 .

Merge consecutive groups together to form a new string.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.