Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxBoxesInWarehouse(vector<int>& boxes, vector<int>& warehouse) {
- // Sort boxes according to height.
- sort(boxes.begin(), boxes.end());
- // Find min height box that can fit at each room.
- for(int i=1; i<warehouse.size(); i++)
- warehouse[i] = min(warehouse[i], warehouse[i-1]);
- // Fit the boxes.
- int count = 0;
- for(int i=warehouse.size()-1; i>=0; i--){
- if(count < boxes.size() && boxes[count] <= warehouse[i])
- count++;
- }
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment