Leetcode Problem 1564. Put Boxes Into the Warehouse I
1564. Put Boxes Into the Warehouse I
Leetcode Solutions
Add Smallest Boxes to the Rightmost Warehouse Rooms
Preprocess the warehouse heights to make them non-increasing from left to right.
Sort the boxes in ascending order based on their heights.
Initialize a count to keep track of the number of boxes placed.
Use two pointers: one for the boxes (starting from the smallest) and one for the warehouse rooms (starting from the rightmost).
While both pointers are valid:
a. If the current box can fit in the current warehouse room, place the box, increment the count, and move to the next box and the next room to the left.
b. If the current box cannot fit, move to the next room to the left without changing the box pointer.