This problem seems a bit difficult to think, however, given some time of thinking, we know that this problem is like an enhancement of sorting the array and we find out how to put consecutive numbers into boxes.
So my idea to solve this problem to sort the array first. then we just put the element into the boxes, in the meantime, we delete the item from the array.
It is only True
if every box if filled up with W
elements and the array hand
is empty.