diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 781a3d7..73837e4 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -218,4 +218,5 @@ mod p3145_find_products_of_elements_of_big_array; mod p3146_permutation_difference_between_two_strings; mod p698_partition_to_k_equal_sum_subsets; mod p3134_find_the_median_of_the_uniqueness_array; -mod p3144_minimum_substring_partition_of_equal_character_frequency; \ No newline at end of file +mod p3144_minimum_substring_partition_of_equal_character_frequency; +mod p3142_check_if_grid_satisfies_conditions; \ No newline at end of file diff --git a/src/problem/p3142_check_if_grid_satisfies_conditions.rs b/src/problem/p3142_check_if_grid_satisfies_conditions.rs new file mode 100644 index 0000000..3f779b1 --- /dev/null +++ b/src/problem/p3142_check_if_grid_satisfies_conditions.rs @@ -0,0 +1,42 @@ +/** + * [3142] Check if Grid Satisfies Conditions + */ +pub struct Solution {} + + +// submission codes start here + +impl Solution { + pub fn satisfies_conditions(grid: Vec>) -> bool { + let (m, n) = (grid.len(), grid[0].len()); + + for i in 0..n { + if i != 0 && grid[0][i] == grid[0][i - 1] { + return false; + } + + for j in 1..m { + if grid[j][i] != grid[j - 1][i] { + return false; + } + } + } + + true + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_3142() { + assert!(Solution::satisfies_conditions(vec![vec![1, 0, 2], vec![1, 0, 2]])); + assert!(!Solution::satisfies_conditions(vec![vec![1, 1, 1], vec![0, 0, 0]])); + assert!(Solution::satisfies_conditions(vec![vec![0]])); + assert!(!Solution::satisfies_conditions(vec![vec![1], vec![2], vec![3]])); + } +}