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 email@example.com. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Maximum size square sub-matrix with all 1s
- Print a given matrix in spiral form
- Search in a row wise and column wise sorted matrix
- A Boolean Matrix Question
- Performance analysis of Row major and Column major order of storing arrays in C
- Matrix Chain Multiplication | DP-8
- Print unique rows in a given boolean matrix
- Inplace (Fixed space) M x N size matrix transpose | Updated
- Maximum sum rectangle in a 2D matrix | DP-27
- Zigzag (or diagonal) traversal of Matrix
- Divide and Conquer | Set 5 (Strassen's Matrix Multiplication)
- Print all possible paths from top left to bottom right of a mXn matrix
- Count all possible paths from top left to bottom right of a mXn matrix
- Kth smallest element in a row-wise and column-wise sorted 2D array | Set 1
- Printing brackets in Matrix Chain Multiplication Problem