Groups by Remainder
Group the values of nums by their remainder when divided by k. All values are non-negative, so the remainders run from 0 to k - 1.
Return the non-empty groups as a list of lists, ordered by remainder from smallest to largest. Inside a group, keep the values in the order they have in nums. The empty list gives [].
Example 1
nums [5,3,8,1,6,9]
k 3
returns [[3,6,9],[1],[5,8]]
Remainder 0: 3, 6, 9; remainder 1: 1; remainder 2: 5, 8. Groups come out in remainder order.
Example 2
nums [4,8,12]
k 4
returns [[4,8,12]]
Every value is a multiple of 4, so there is one group with remainder 0.
Constraints
0 <= len(nums) <= 1000 <= nums[i] <= 10001 <= k <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.