Skip to content

Commit e8ff4eb

Browse files
committed
2187. Minimum Time to Complete Trips: RETRY
1 parent 3d6532f commit e8ff4eb

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,3 +1653,4 @@ mod s2182_construct_string_with_repeat_limit;
16531653
mod s2183_count_array_pairs_divisible_by_k;
16541654
mod s2185_counting_words_with_a_given_prefix;
16551655
mod s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii;
1656+
mod s2187_minimum_time_to_complete_trips;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* [2187] Minimum Time to Complete Trips
3+
*
4+
* You are given an array time where time[i] denotes the time taken by the i^th bus to complete one trip.
5+
* Each bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.
6+
* You are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.
7+
*
8+
* Example 1:
9+
*
10+
* Input: time = [1,2,3], totalTrips = 5
11+
* Output: 3
12+
* Explanation:
13+
* - At time t = 1, the number of trips completed by each bus are [1,0,0].
14+
* The total number of trips completed is 1 + 0 + 0 = 1.
15+
* - At time t = 2, the number of trips completed by each bus are [2,1,0].
16+
* The total number of trips completed is 2 + 1 + 0 = 3.
17+
* - At time t = 3, the number of trips completed by each bus are [3,1,1].
18+
* The total number of trips completed is 3 + 1 + 1 = 5.
19+
* So the minimum time needed for all buses to complete at least 5 trips is 3.
20+
*
21+
* Example 2:
22+
*
23+
* Input: time = [2], totalTrips = 1
24+
* Output: 2
25+
* Explanation:
26+
* There is only one bus, and it will complete its first trip at t = 2.
27+
* So the minimum time needed to complete 1 trip is 2.
28+
*
29+
*
30+
* Constraints:
31+
*
32+
* 1 <= time.length <= 10^5
33+
* 1 <= time[i], totalTrips <= 10^7
34+
*
35+
*/
36+
pub struct Solution {}
37+
38+
// problem: https://leetcode.com/problems/minimum-time-to-complete-trips/
39+
// discuss: https://leetcode.com/problems/minimum-time-to-complete-trips/discuss/?currentPage=1&orderBy=most_votes&query=
40+
41+
// submission codes start here
42+
43+
impl Solution {
44+
pub fn minimum_time(time: Vec<i32>, total_trips: i32) -> i64 {
45+
0
46+
}
47+
}
48+
49+
// submission codes end
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
55+
#[test]
56+
#[ignore]
57+
fn test_2187_example_1() {
58+
let time = vec![1, 2, 3];
59+
let total_trips = 5;
60+
61+
let result = 3;
62+
63+
assert_eq!(Solution::minimum_time(time, total_trips), result);
64+
}
65+
66+
#[test]
67+
#[ignore]
68+
fn test_2187_example_2() {
69+
let time = vec![2];
70+
let total_trips = 1;
71+
72+
let result = 2;
73+
74+
assert_eq!(Solution::minimum_time(time, total_trips), result);
75+
}
76+
}

0 commit comments

Comments
 (0)