Given a matrix mat, we have to check if the sum of i-th row is equal to the sum of i-th column or not.
Input : 1 2 3 4 9 5 3 1 0 3 5 6 0 4 5 6 Output : Yes Sums of 1st row = 10 and 1st column are same, i.e., 10
Expected time complexity is O(m x n) where m is number of rows and n is number of columns.
The idea is really simple. We use a nested loop to calculate sum of each row and column and then check whether their sum is equal or not.
The implementation of the above idea is given below.
This article is contributed by Sarthak Kohli. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Construct a matrix such that union of ith row and ith column contains every element from 1 to 2N-1
- Find if a binary matrix exists with given row and column sums
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Check if the given matrix is increasing row and column wise
- Check if it is possible to create a matrix such that every row has A 1s and every column has B 1s
- Check whether row or column swaps produce maximum size binary sub-matrix with all 1s
- Number of positions with Same address in row major and column major order
- Print all elements in sorted order from row and column wise sorted matrix
- Find sum of all elements in a matrix except the elements in row and/or column of given cell?
- Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1.
- Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix
- Count zeros in a row wise and column wise sorted matrix
- Sum of matrix in which each element is absolute difference of its row and column numbers
- Sum of matrix element where each elements is integer division of row and column
- Minimum operations required to make each row and column of matrix equals
- Sort the matrix row-wise and column-wise
- Sum of middle row and column in Matrix
- Program to find the Sum of each Row and each Column of a Matrix
- Minimum element of each row and each column in a matrix