Binary Matrix

3.8

10 votes
Algorithms, Easy, Greedy Algorithms, Implementation, String Manipulation
Problem

N numbers were converted into their respective Binary form of M length and arranged in an NxM matrix.

Your task is to find the index of row (1 based indexing) which contains the binary number with maximum value. If multiple rows have maximum value then print the row with minimum index.

Input:

The first line contains two space separated integers N and M, denoting number of rows and number of columns in matrix respectively.

Each of the next N lines contains a number in binary form.

Output:

Print the index of row in a single line.

Constraints:

\(1 \le N,M \le 10^3\)
\(0 \le mat[i][j] \le 1\)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

1st row value  =  2*1  +  2*0 + 21 *1 + 2*0  =  10

2nd row value =  2*0  +  2*1 + 21 *0 + 2*0  =  4

3rd row value  =  2*0  +  2*0 + 21 *1 + 2*0  =  2

4th row value  =  2*0  +  2*0 + 21 *1 + 2*1  =  3

Editor Image

?