1. The matrix may also contain some negative elements.
2. A square matrix is a matrix with the same number of rows and columns.
A matrix obtained by deleting some (possibly zero) of the rows and/or columns from the beginning and/or from the end of a matrix is said to be a sub-matrix of the given matrix.
Example: Given a matrix
A = 1 2
3 4
Possible non-empty sub-matrices of A are represented below by bold numbers-
The first line of input contains T, denoting the number of test cases.
The first line of each test case contains an integer N, the order of the square matrix.
The following N lines contain N space-separated integers, representing the elements in the ith row of the matrix 'MAT'.
The only line of output of each test case should contain an integer denoting the number of non-empty sub-matrices such that the sum of all the elements inside the sub-matrix is equal to zero.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 70
Time Limit: 1 sec
As it is clear from the hint itself, we will start by converting this problem to a 1D version. Let’s say we have a matrix name M. Now to convert M from 2D to 1D, we will try to compress the columns between 2 fixed rows, and then we will solve the 1D version on the compressed array. Let’s understand how we will achieve this.
8 5 7
3 7 -8
5 -8 9
-8 5 7
-8 5 7
3 7 -8
-8 5 7
3 7 -8
5 -8 9
SudoKube
SudoKube
SudoKube
King Placement
Ninja and the experiment
Search In A Sorted 2D Matrix
Spiral Matrix