47. Chunk an Array
EasyArray
Split the array into consecutive groups of size k (the last group may be smaller). Print each group on its own line.
Input format
Line 1: n k Line 2: n integers
Output format
One group per line.
Example 1
Input
5 2 1 2 3 4 5
Output
1 2 3 4 5
Example 2
Input
4 4 1 2 3 4
Output
1 2 3 4
Constraints
1 ≤ k ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…