← Questions

Leftmost column with a one in a row-sorted binary matrix

0
UberCodingLast asked May 2026

In an m x n matrix of 0s and 1s, each row has all its 0s before its 1s. Return the index of the leftmost column that holds a 1, or -1 if there is none.

Start with a binary search on each row, then improve to O(m + n) by walking from the top-right corner.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding