Skip to content

Practice Count Submatrices With All Ones

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1504
LeetCode Problem

Count Submatrices With All Ones

Problem Statement

Given an m x n binary matrix mat, return the number of submatrices that have all ones.

Source: Count Submatrices With All Ones on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
mat = [[1,0,1],[1,1,0],[1,1,0]]
Output
13

# Example 2

Input
mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]
Output
24

Constraints

1 <= m, n <= 150
mat[i][j] is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Count Submatrices With All Ones.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.