Skip to content

Commit

Permalink
Create 12. Minimum Time to Complete Trips.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb authored Mar 7, 2023
1 parent bead43b commit 994e1a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 11_Binary-Search/12. Minimum Time to Complete Trips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://leetcode.com/problems/minimum-time-to-complete-trips/

class Solution:
def minimumTime(self, time: List[int], totalTrips: int) -> int:

def check(curTime):
tripsCount = 0
for t in time:
tripsCount += curTime // t
return tripsCount >= totalTrips

l = 0
r = min(time) * totalTrips + 1
while l <= r:
mid = l + (r - l) // 2
if check(mid):
r = mid - 1
else:
l = mid + 1

return l



# Time: O(N log(N))

0 comments on commit 994e1a3

Please sign in to comment.