Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

Determine the row index with minimum number of ones. The given 2D matrix has only zeroes and ones and also the matrix is sorted row wise. If two or more rows have same number of **1's** than print the row with **smallest index**.

**Input:**

The first line of input contains an integer **T **denoting the number of test cases. The first line of each test case consists of two integer **n** and **m**. The next line consists of **n*m** spaced integers.

**Output:**

Print the index of the row with minimum number of 1's. If there is 0 number of '1' in the matrix then, print '**-1**'.

**Constraints: **

1 <= T <= 103

1 <= n, m <= 100

**Example:
Input:**

2

3 3

0 0 0 0 0 0 0 0 0

4 4

0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 1

**Output:**

-1

0

**Explanation:
Testcase **

0 0 0 1

0 1 1 1

0 0 1 1

0 0 1 1

First row is having minimum number of 1 i.e. answer is 0.

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?

Yes
Row with minimum number of 1's

...