storage capacity
user_8886827
python
a year ago
806 B
11
Indexable
def storage_capacity(box_heights, shelf_heights):
box_count = 0
last_filled_shelf = len(shelf_heights)
result = [-1]*len(shelf_heights)
for box_height in box_heights:
shelf_idx = 0
while box_height<=shelf_heights[shelf_idx] and shelf_idx<last_filled_shelf-1:
shelf_idx+=1
result[shelf_idx]=box_height
last_filled_shelf=shelf_idx-1
box_count+=1
if last_filled_shelf==-1:
return box_count
return box_count
shelf_heights = [3, 4, 2, 3]
box_heights = [2, 3, 3, 4, 5]
print(storage_capacity(box_heights, shelf_heights)) ## (box2,box1,empty,box0)
box_heights = [3, 3, 3]
print(storage_capacity(box_heights, shelf_heights))
box_heights = [8, 3, 3]
print(storage_capacity(box_heights, shelf_heights))Editor is loading...
Leave a Comment