144. Count Rectangles with All Ones

HardArrayArray

Given a binary matrix, return the number of submatrices (rectangles) that contain only 1s. Input: JSON 2D grid of 0/1.

Input: A JSON 2D 0/1 grid.

Output: Integer — count of all-ones submatrices.

Examples

Example 1
Input: [[1,0,1],[1,1,0],[1,1,0]]
Output: 13
Explanation: 13 all-ones submatrices.
Example 2
Input: [[1]]
Output: 1
Explanation: Single 1.
Example 3
Input: [[0]]
Output: 0
Explanation: No ones.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →