Leetcode 2138: Divide a String Into Groups of Size k
In this problem, we divide a String into a list of substrings of size k. In the last String is not of size k, we complete the string with a
fill character until the string is of size k.
s = "abcdef", k = 4, fill = 'x'Return: ["abcd", "efxx"]
- First, we want all the substrings of size k by using the function
substringin a loop. In the loop we will keep track of an index
0and incremented of
kafter each iteration.
- The loop stops when…