Count Submatrices
MATRIX

Problem

Given a 2D matrix mat which may contain both positive and negative integers, return the total number of non-empty submatrices that sum to zero.

Examples

countZeroSumSubmatrices([ [0, 2, -3], [1, -3, 1], [1, -2, 1] ]) // returns 3 /* The function identifies the following submatrices with a sum of zero: 1. A 1x1 zone at the position [0,0]: [[0]] 2. A 2x2 zone at the position [0,0]: [[0,2],[1,-3]] 3. A 1x3 zone at the position [0,2]: [[1,-2,1]] */
Loading...