Skip to main content
mediumNeetCode 150

Search a 2D Matrix

Given a 2D matrix where: - Each row is sorted in ascending order - First element of each row > last element of previous row Return true if target exists in matrix, false otherwise Must use O(log(m*n)) time complexity Example: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 => true

Binary search is the tool here, but the real test is whether your invariant stays crisp. Interviewers love it because it reveals your boundary precision and your edge-case discipline. Interviewers care more about airtight boundaries than speed here.

Arrays & HashingBinary Search

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Search Sorted 2D Matrixmedium
Based onLeetCode