diff --git a/src/problem/mod.rs b/src/problem/mod.rs index c6d3369..851cda5 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -332,3 +332,5 @@ mod p3244_shortest_distance_after_road_addition_queries_ii; mod p3248_snake_in_matrix; mod p3233_find_the_count_of_numbers_which_are_not_special; + +mod p3238_find_the_number_of_winning_players; diff --git a/src/problem/p3238_find_the_number_of_winning_players.rs b/src/problem/p3238_find_the_number_of_winning_players.rs new file mode 100644 index 0000000..feeb865 --- /dev/null +++ b/src/problem/p3238_find_the_number_of_winning_players.rs @@ -0,0 +1,58 @@ +/** + * [3238] Find the Number of Winning Players + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn winning_player_count(n: i32, pick: Vec>) -> i32 { + use std::collections::HashMap; + let n = n as usize; + + let mut player = vec![HashMap::new(); n]; + for p in pick { + let (p, b) = (p[0] as usize, p[1]); + + let mut entry = player[p].entry(b).or_insert(0); + *entry += 1; + } + + player + .iter() + .enumerate() + .filter_map(|(i, map)| { + if map.iter().any(|(_, v)| *v > i) { + Some(()) + } else { + None + } + }) + .count() as i32 + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_3238() { + assert_eq!( + 2, + Solution::winning_player_count( + 4, + vec![ + vec![0, 0], + vec![1, 0], + vec![1, 0], + vec![2, 1], + vec![2, 1], + vec![2, 0] + ] + ) + ); + } +}