Skip to content

Commit 49c13d7

Browse files
committed
Add problem 3168: Minimum Number of Chairs in a Waiting Room
1 parent b6b5cb7 commit 49c13d7

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,7 @@ pub mod problem_3160_find_the_number_of_distinct_colors_among_the_balls;
21172117
pub mod problem_3162_find_the_number_of_good_pairs_i;
21182118
pub mod problem_3163_string_compression_iii;
21192119
pub mod problem_3164_find_the_number_of_good_pairs_ii;
2120+
pub mod problem_3168_minimum_number_of_chairs_in_a_waiting_room;
21202121
pub mod problem_3350_adjacent_increasing_subarrays_detection_ii;
21212122

21222123
#[cfg(test)]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
pub struct Solution;
2+
3+
// ------------------------------------------------------ snip ------------------------------------------------------ //
4+
5+
impl Solution {
6+
pub fn minimum_chairs(s: String) -> i32 {
7+
let mut total = 0;
8+
let mut empty = 0;
9+
10+
for c in s.bytes() {
11+
if c == b'E' {
12+
if empty == 0 {
13+
total += 1;
14+
} else {
15+
empty -= 1;
16+
}
17+
} else {
18+
empty += 1;
19+
}
20+
}
21+
22+
total
23+
}
24+
}
25+
26+
// ------------------------------------------------------ snip ------------------------------------------------------ //
27+
28+
impl super::Solution for Solution {
29+
fn minimum_chairs(s: String) -> i32 {
30+
Self::minimum_chairs(s)
31+
}
32+
}
33+
34+
#[cfg(test)]
35+
mod tests {
36+
#[test]
37+
fn test_solution() {
38+
super::super::tests::run::<super::Solution>();
39+
}
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub mod brute_force;
2+
3+
pub trait Solution {
4+
fn minimum_chairs(s: String) -> i32;
5+
}
6+
7+
#[cfg(test)]
8+
mod tests {
9+
use super::Solution;
10+
11+
pub fn run<S: Solution>() {
12+
let test_cases = [("EEEEEEE", 7), ("ELELEEL", 2)];
13+
14+
for (s, expected) in test_cases {
15+
assert_eq!(S::minimum_chairs(s.to_string()), expected);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)