Sobes.tech
Junior — Senior

Determining the row with the most ones in an ordered binary matrix

livecode

Task condition

Given an N x N square matrix filled with zeros and ones. In each row, after the first encountered one, all subsequent elements are also ones. Find the index of the row containing the maximum number of ones in the minimum possible time.

Example matrix:

arr = [
    [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]
]