Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6564 |

@blackshadows | 6400 |

@mb1973 | 5785 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4639 |

@sanjay05 | 3762 |

@mantu_singh | 3712 |

@gfgaccount | 3627 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@yaswanthero123 | 625 |

@vikash619 | 611 |

@venkat11803610 | 501 |

@roshan13ar | 396 |

@DevangSingh | 379 |

@ravi11815721 | 312 |

@hrishipangavhane | 286 |

@aryanjain85297 | 280 |

@kommaraju11806903 | 277 |

@infosumitraut | 272 |

@ankitsharma5422 | 256 |

Complete Leaderboard |

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]<=10^{3}

Login to report an issue on this page.

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

YesLoading...

Sums of i-th row and i-th column

...