LC: 1564. Put Boxes Into the Warehouse I - spiralgo/algorithms GitHub Wiki

1564. Put Boxes Into the Warehouse I:

The Essence:

When placing the boxes, the higher boxes should be non-prioritized. This makes sense, because if a large box can get through a room, it perhaps won't be able to get through next rooms, which are more suitable for smaller boxes.

Details:

The array of boxes can be sorted. Then, looping down from the largest box, we can check if the box fits into the current room, which we initially set with index 0. We increment the room index when the box fits.