Junior — Senior
Finding the row with the highest number of ones in a sorted binary matrix
livecode
Task condition
Given a square matrix N×N filled with zeros and ones. In each row, all zeros are on the left, and after the first one in the row, only ones follow. The task is to determine the index of the row containing the maximum number of ones in the minimum possible time.
Example matrix:
matrix = [
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 1, 1],
[0, 0, 0, 1, 1, 1],
[0, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 1],
[0, 0, 0, 1, 1, 1]
]