Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Divide a String Into Groups of Size k

XPChallenge Points: 10
levelLevel: Easy

You are given:

  • A string s

  • A group size k

  • A fill character fill

We divide the string into groups of size k, in order:

  1. The first group uses the first k characters, the second group uses the next k, and so on.

  2. If the final group has fewer than k characters, you must append the fill character until the group reaches size k.

  3. After removing any added fill characters and concatenating the groups, we must get back the original string s.

Your task is to return an array of all the groups after applying this procedure.

Example 1:

Input: s = "abcdefghi", k = 3, fill = "x"

Output: ["abc","def","ghi"]

Explanation:

Every group naturally contains 3 characters, so no fill characters are needed.

Example 2:

Input: s = "abcdefghij", k = 3, fill = "x"

Output: ["abc","def","ghi","jxx"]

Explanation:

The last group contains "j" from the string and requires two 'x' fill characters to reach size 3.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result