Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.45 KB

_1580. Put Boxes Into the Warehouse II.md

File metadata and controls

51 lines (35 loc) · 1.45 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 15, 2024

Last updated : June 15, 2024


Related Topics : Array, Greedy, Sorting

Acceptance Rate : 66.02 %


Solutions

Python

class Solution:
    def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:
        
        maxWarehouse = [warehouse[0]] + [0] * (len(warehouse) - 2) + [warehouse[-1]]

        for i in range(1, len(warehouse)) :
            maxWarehouse[i] = min(maxWarehouse[i - 1], warehouse[i])

        maxWarehouse[-1] = max(maxWarehouse[-1], warehouse[-1])
        for i in range(len(warehouse) - 2, -1, -1) :
            maxWarehouse[i] = min(warehouse[i], max(maxWarehouse[i + 1], maxWarehouse[i]))

        maxWarehouse.sort()
        boxes.sort()

        counter = 0
        while maxWarehouse and boxes :
            if boxes[-1] <= maxWarehouse[-1] :
                counter += 1
                maxWarehouse.pop()
            boxes.pop()

        return counter