FunctionRacerProblemsRace

Search a Sorted Matrix

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

Every row of matrix is sorted left to right, and the first number of each row is bigger than the last number of the row above it. Return True if target appears anywhere in the grid, otherwise False.

Hint: you can treat the whole grid as one long sorted list.

Example 1

matrix [[1,3,5,7],[10,11,16,20],[23,30,34,60]]
target 16
returns true

16 is in the second row.

Example 2

matrix [[1,3,5,7],[10,11,16,20],[23,30,34,60]]
target 13
returns false

13 is nowhere.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems