Search a 2D Matrix II
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an m x n integer grid matrix with two ordering guarantees: every row is sorted in non-decreasing order from left to right, and every column is sorted in non-decreasing order from top to bottom. Rows are **not** required to continue where the previous row ended, so the grid as a whole is not one sorted list.
Return true if the integer target appears anywhere in matrix, and false otherwise.
Aim for O(m + n) time. Scanning every cell works but ignores the structure the grid gives you.
Examples
Constraints
- 1 <= m, n <= 300
- -10^9 <= matrix[i][j], target <= 10^9
- Each row is non-decreasing left to right
- Each column is non-decreasing top to bottom
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.