Split into batches

Write codeEasy10 min

Your task

A fulfilment system processes orders in batches. Given a list of order IDs in queue order and a batch size k (k >= 1), split the queue into consecutive batches of k orders each; the final batch keeps whatever is left over, even if fewer than k. Return the batches as a list of lists. Example: [1, 2, 3, 4, 5] with k = 2 becomes [[1, 2], [3, 4], [5]].

Examples

batch_orders(order_ids: list[int], k: int) -> list[list[int]]
Example 1
Inputbatch_orders([1, 2, 3, 4, 5], 2)
Output[[1, 2], [3, 4], [5]]