Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Complete Leaderboard
Sums of i-th row and i-th column
Basic Accuracy: 46.75% Submissions: 890 Points: 1

Given a matrix A of dimensions NxM. Check whether the sum of a row is equal to the corresponding column or not i.e. whether the sum of the ith row is equal to the sum of the ith column.
Note: Check only up to valid row and column numbers i.e if the dimensions are 3x5, check only for the first 3 rows and columns.

Example 1:

Input:
N=2,M=2
A=[[1,2],[2,1]]
Output:
1
Explanation:
The sum of 1st row is equal to sum of
1st column and also sum of 2nd row is equal 
to the sum of 2nd column.So, Answer is 1.

Example 2:

Input:
N=1,M=3
A=[[5],[0],[0]]
Output:
1
Explanation:
The sum of 1st column is equal
to the sum of 1st row.Thus,answer is 1.
(We do not check for the 2nd and 3rd rows
because there are no 2nd and 3rd columns.)


Your Task:
You don't need to read input or print anything. Your task is to complete the function sumOfRowCol() which takes two integers N, M and a 2D array A as input parameters and returns 1 if all the valid sum of rows is equal to the valid sum of columns. Otherwise, returns 0.


Expected Time Complexity:O(N*M)
Expected Auxillary Space:O(min(N,M))

 

Constraints:
1<=N,M,A[i][j]<=103

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Sums of i-th row and i-th column

Output Window