diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 5c9ec92..b6f8206 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -336,3 +336,5 @@ mod p3233_find_the_count_of_numbers_which_are_not_special; mod p3238_find_the_number_of_winning_players; mod p632_smallest_range_covering_elements_from_k_lists; + +mod p3206_alternating_groups_i; diff --git a/src/problem/p3206_alternating_groups_i.rs b/src/problem/p3206_alternating_groups_i.rs new file mode 100644 index 0000000..cf2f1c4 --- /dev/null +++ b/src/problem/p3206_alternating_groups_i.rs @@ -0,0 +1,42 @@ +/** + * [3206] Alternating Groups I + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn number_of_alternating_groups(colors: Vec) -> i32 { + let n = colors.len(); + + let mut result = 0; + + for i in n..2 * n { + let left = (i - 1) % n; + let middle = i % n; + let right = (i + 1) % n; + + if colors[left] != colors[middle] && colors[right] != colors[middle] { + result += 1; + } + } + + result + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_3206() { + assert_eq!(0, Solution::number_of_alternating_groups(vec![0, 0, 0])); + assert_eq!( + 3, + Solution::number_of_alternating_groups(vec![0, 1, 0, 0, 1]) + ); + } +}