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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find if a binary matrix exists with given row and column sums
- 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 whether row or column swaps produce maximum size binary sub-matrix with all 1s
- Check if the rows of a binary matrix can be made unique by removing a single column
- Efficiently compute sums of diagonals of a matrix
- Print cells with same rectangular sums in a matrix
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Center element of matrix equals sums of half diagonals
- Sum of middle row and column in Matrix
- Print an N x M matrix such that each row and column has all the vowels in it
- Maximum sum of a Matrix where each value is from a unique row and column
- 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
- Print matrix in zig-zag fashion from the last column
- Find column with maximum sum in a Matrix
- Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1.
- Product of middle row and column in an odd square matrix
- Find a Square Matrix such that sum of elements in every row and column is K
- Find maximum element of each column in a matrix