Medium · Binary Search

Leftmost Column with at Least a One

Given a binary matrix whose rows are each sorted in non-decreasing order (all 0s before 1s), read through BinaryMatrix.get(row, col) and dimensions(), return the index of the leftmost column that contains a 1, or −1 if the matrix has no 1.

Examples

Example 1

[[0,0,0,1],[0,0,1,1],[0,1,1,1]]

Output: column 1

Example 2

[[0,0,0],[0,0,0],[0,0,0]]

Output: -1 (no 1)

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Binary Search problems