Skip to main content

1564 - Put Boxes Into the Warehouse I

Details

KeyValue
Linkhttps://leetcode.com/problems/put-boxes-into-the-warehouse-i/
LanguagePython 3
Runtime741 ms, faster than 62.03% of Python3 online submissions for Put Boxes Into the Warehouse I
Memory Usage33.2 MB, less than 35.44% of Python3 online submissions for Put Boxes Into the Warehouse I
DatastructuresList[int]
AlgorithmsGreedy
ComplexityTime: O(NlogN+M) Memory: O(1) (N=number of boxes, M=number of warehouses)

Procedure

  1. ...

Code

class Solution:
def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:
boxes.sort()
number_of_warehouses = len(warehouse)
number_of_boxes = len(boxes)
result = 0

for i in range(number_of_boxes-1, -1, -1):
if boxes[i] <= warehouse[result]:
result += 1
if result == number_of_warehouses:
return number_of_warehouses

return result