Coding

Search a 2D matrix where each row and column is sorted.

Write an efficient algorithm that searches for a value target in an m x n integer matrix. Integers in each row are sorted, and the first integer of each row is greater than the last integer of the previous row.

Input: matrix = [[1,4],[2,5]], target = 20

Output: FALSE

Explanation: The target 20 is strictly greater than the largest element in the matrix (5), so the search fails immediately.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions