Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3212 - Count Submatrices With Equal Frequency of X and Y\.

    Medium

    Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contains:

    • grid[0][0]

    • an equal frequency of 'X' and 'Y'.

    • at least one 'X'.

    Example 1:

    Input: grid = \[\["X","Y","."],"Y",".","."]

    Output: 3

    Explanation:

    Example 2:

    Input: grid = \[\["X","X"],"X","Y"]

    Output: 0

    Explanation:

    No submatrix has an equal frequency of 'X' and 'Y'.

    Example 3:

    Input: grid = \[\[".","."],".","."]

    Output: 0

    Explanation:

    No submatrix has at least one 'X'.

    Constraints:

    • 1 <= grid.length, grid[i].length <= 1000

    • grid[i][j] is either 'X', 'Y', or '.'.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer numberOfSubmatrices(Array<CharArray> grid)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait