File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
problem_3168_minimum_number_of_chairs_in_a_waiting_room Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -2117,6 +2117,7 @@ pub mod problem_3160_find_the_number_of_distinct_colors_among_the_balls;
21172117pub mod problem_3162_find_the_number_of_good_pairs_i;
21182118pub mod problem_3163_string_compression_iii;
21192119pub mod problem_3164_find_the_number_of_good_pairs_ii;
2120+ pub mod problem_3168_minimum_number_of_chairs_in_a_waiting_room;
21202121pub mod problem_3350_adjacent_increasing_subarrays_detection_ii;
21212122
21222123#[ cfg( test) ]
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments