Need help on this matrix question

A binary matrix of nxm was given, you have to toggle any column k number of times so that you can get the maximum number of rows having all 1’s.

for eg, n=3, m=3,

   1 0 0

    1 0 1

    1 0 0

if k=2, then we will toggle column 2 and 3 once and we will get rows 1 and 3 with 1 1 1 and 1 1 1 i.e. all 1’s so answer is 2 as there are 2 rows with all 1’s.

if k=3, then we will toggle column 2 thrice and we will get row 2 with 1 1 1 i.e. all 1’s so answer is 1 as there is 1 row with all 1’s.

no of rows = pow(10,5)

As the row which will become all ones need to be the same, count the row which is occuring the maximum number of times in the matrix, of those rows take the ones where noOfZeroes < k and (noOfZeroes-k)%2 == 0.

2 Likes