forked from ravitandon90/Code-Submissions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Priya-Arora
28 lines (21 loc) · 951 Bytes
/
Priya-Arora
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
class Solution:
def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:
"""
This is finding the maximum no of boxes that can be fit in the given truck
"""
if truckSize <=0:
return sys.minsize
# Sort as per the no of units as this is the value we are gonna maximize
result = sorted(boxTypes, key=lambda t: t[1], reverse=True)
sz=0
maxUnits=0
for noBoxes, unitsPerBox in result:
if sz < truckSize and (truckSize - sz) < noBoxes:
temp = (truckSize - sz)
sz = sz + (truckSize - sz)
maxUnits = maxUnits + (temp* unitsPerBox)
elif sz < truckSize and (truckSize - sz) >= noBoxes:
sz = sz + noBoxes
maxUnits = maxUnits + noBoxes * unitsPerBox
return maxUnits