Skip to content
LC-2138 Easy LeetCode

2138. Divide a String Into Groups of Size k

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 67% Topics: String, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# string
class Solution(object):
    def divideString(self, s, k, fill):
        """
        :type s: str
        :type k: int
        :type fill: str
        :rtype: List[str]
        """
        return [s[i:i+k] + fill*(i+k-len(s)) for i in xrange(0, len(s), k)]

Solution from kamyu104/LeetCode-Solutions · MIT