File tree 1 file changed +10
-9
lines changed
scripts/algorithms/M/Minimum Time to Complete Trips
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 736 ms (Top 18.65%) | Memory: 94.5 MB (Top 68.73%)
1
2
class Solution {
2
3
public:
3
4
long long minimumTime (vector<int >& time, int totalTrips) {
4
5
long long anstillnow=-1 ;
5
-
6
- long long left=1 , right= 100000000000001 ; // can also write this as 1+1e14
7
-
6
+
7
+ long long left=1 , right= 100000000000001 ; // can also write this as 1+1e14
8
+
8
9
while (left<=right){
9
- long long mid= left+ (right-left)/2 ; // find mid point like this to avoid overflow
10
+ long long mid= left+ (right-left)/2 ; // find mid point like this to avoid overflow
10
11
long long curr_trips=0 ;
11
12
for (int t: time ){
12
13
curr_trips+= mid/t;
13
14
}
14
-
15
- if (curr_trips>=totalTrips){
15
+
16
+ if (curr_trips>=totalTrips){
16
17
anstillnow=mid;
17
18
right=mid-1 ;
18
19
}
19
-
20
+
20
21
else {
21
22
left=mid+1 ;
22
23
}
23
24
}
24
-
25
+
25
26
return anstillnow;
26
27
}
27
- };
28
+ };
You can’t perform that action at this time.
0 commit comments