Given a 2D binary matrix A of dimensions NxM, determine the row that contains a minimum number of 1's.
Note-The matrix contains only 1s and 0s. Also, if two or more rows contain the minimum number of 1's, the answer is the lowest of those indices.
Rows 2 and 3 contain the minimum number
of 1's(2 each).Since, 2 is less than 3.
Thus, the answer is 2.
All the rows contain the same number
of 1's(0 each).Among them, index 1
is the smallest, so the answer is 1.
You don't need to read input or print anything. Your task is to complete the function minRow() which takes the two integers N, M as well as the 2D matrix A as input parameters and returns the minimum index of the row which contains the least number of 1's.
Expected Time Complexity:O(N*M) Expected Auxillary Space:O(1)