Leetcode 1564. Put Boxes Into the Warehouse I
Given arrays of box heights and warehouse room heights, maximize how many boxes can be placed knowing a box can only reach a room if its height is ≤ the minimum height along the path to that room (so each room's effective capacity is its prefix minimum). The core challenge is a greedy matching problem using prefix minima on warehouse heights and sorting/two-pointer placement of boxes.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late July, 2026
You have two arrays: boxes containing heights of boxes (all unit width) and warehouse containing heights of n rooms in a warehouse. The warehouse rooms are numbered from 0 to n-1 from left to right, where warehouse[i] represents the height of room i. The rules for placing boxes are: Boxes cannot be stacked on top of each other You can rearrange the boxes in any order you want You can push boxes into the warehouse from either the left side or the right side When pushing a box through the warehouse, if it encounters a room with height less than the box's height, the box gets stuck there and cannot go further. All subsequent boxes pushed from the same side will also be blocked Your goal is to find the maximum number of boxes that can be placed in the warehouse. For example, if you have a warehouse with room heights [4, 3, 5, 2, 6] and you're pushing a box of height 4 from the left, it will stop at room index 1 (height 3). If you push the same box from the right, it will stop at room index 3 (height 2).
Hello Interview Premium
Your account is free and you can post anonymously if you choose.