FunctionRacerProblemsRace

Chunks From the Left

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

Cut s into pieces of k characters each, starting from the left, and return the pieces as a list in order. The last piece is shorter than k when the length of s is not a multiple of k; it is never padded. An empty s gives an empty list.

Example 1

s "abcdefg"
k 3
returns ["abc","def","g"]

Seven characters cut into threes give abc, def and the leftover g.

Example 2

s "abcdef"
k 2
returns ["ab","cd","ef"]

Six characters cut into twos give exactly three full pieces.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems