3212. Count Submatrices With Equal Frequency of X and Y Medium

@problem@discussion
#Array#Matrix#Prefix Sum



1/**
2 * [3212] Count Submatrices With Equal Frequency of X and Y
3 *
4 * Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of <span data-keyword="submatrix">submatrices</span> that contain:
5 * 
6 * 	grid[0][0]
7 * 	an equal frequency of 'X' and 'Y'.
8 * 	at least one 'X'.
9 * 
10 *  
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">grid = [["X","Y","."],["Y",".","."]]</span>
14 * Output: <span class="example-io">3</span>
15 * Explanation:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2024/06/07/examplems.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 175px; height: 350px;" />
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">grid = [["X","X"],["X","Y"]]</span>
21 * Output: <span class="example-io">0</span>
22 * Explanation:
23 * No submatrix has an equal frequency of 'X' and 'Y'.
24 * </div>
25 * <strong class="example">Example 3:
26 * <div class="example-block">
27 * Input: <span class="example-io">grid = [[".","."],[".","."]]</span>
28 * Output: <span class="example-io">0</span>
29 * Explanation:
30 * No submatrix has at least one 'X'.
31 * </div>
32 *  
33 * Constraints:
34 * 
35 * 	1 <= grid.length, grid[i].length <= 1000
36 * 	grid[i][j] is either 'X', 'Y', or '.'.
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/count-submatrices-with-equal-frequency-of-x-and-y/
42// discuss: https://leetcode.com/problems/count-submatrices-with-equal-frequency-of-x-and-y/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn number_of_submatrices(grid: Vec<Vec<char>>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_3212() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.