Leftmost Column with at Least a One
A medium-tier problem at 55% community acceptance, tagged with Array, Binary Search, Matrix. Reported in interviews at SAP and 1 others.
You're staring at a matrix where every row and every column is sorted. Find the leftmost column that has at least one 1 in it. Sounds straightforward until you realize the matrix is hidden and you can only query it. SAP and Uber have both asked this. The naive scan costs you queries fast. The trick is knowing which corner to start from and how binary search cuts your query count from O(m*n) to O(m log n) or better. If this hits your live assessment and you blank on the optimal direction, StealthCoder surfaces the solution invisibly while you're screen-sharing.
Companies that ask "Leftmost Column with at Least a One"
Leftmost Column with at Least a One is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe core trap is thinking you scan left-to-right or top-to-bottom like a normal matrix. You can't afford to. The insight is that you start from the top-right or bottom-left corner, where the sorted properties of rows and columns let you eliminate an entire row or column per query. Most candidates first attempt a full scan or a naive binary search on each row separately, both of which waste queries. The interactive constraint is the actual challenge here. You're being tested on whether you understand that the query cost matters more than the algorithmic complexity class on paper. Binary search on the leftmost 1 position in each row sounds safe until you realize you're doing log n queries per row. Starting from a corner and walking inward, eliminating rows and columns as you go, is the pattern. This is where the 50% acceptance rate sits. StealthCoder handles the direction logic and the boundary cases that trip up candidates under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Leftmost Column with at Least a One recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Leftmost Column with at Least a One interview FAQ
Why is this marked interactive and what does that change?+
You can't see the whole matrix at once. You make queries and get single values back. Every query costs. That flips the problem from 'find the fastest algorithm' to 'minimize queries while finding the answer.' Binary search on each row independently looks right until you realize it's wasteful compared to a corner-walk strategy.
What's the actual optimal strategy here?+
Start from the top-right or bottom-left corner. If you're at top-right and the value is 1, move left (stay in same row). If it's 0, move down (eliminate that row). This way you traverse the matrix boundary in O(m+n) queries, not O(m log n) per row. Direction choice matters because sorted rows and columns work together only from the right corners.
Do SAP and Uber really ask this or is it inflated?+
Both companies are confirmed to have asked it. With a 55% acceptance rate, it's solidly medium-difficulty and not a rare edge case. It shows up when they want to test whether you optimize for query cost under constraints, not just asymptotic complexity.
Will binary search on each row get accepted?+
Technically yes, if your binary search is correct on the row and you find the leftmost 1 across all rows. But it's O(m log n) queries versus O(m+n) for the corner approach. On large matrices the difference is visible. Interviewers at this tier usually push back if you don't arrive at the corner insight naturally.
How do I not mess up the boundary cases?+
Off-by-one errors kill this problem in live interviews. Your loop condition and your pointer updates when moving corners have to align exactly. The edge case is an all-zeros matrix or a matrix where the leftmost 1 is at the boundary. Trace through a 1x1 and a 2x2 before submitting.
Want the actual problem statement? View "Leftmost Column with at Least a One" on LeetCode →