FunctionRacerProblemsRace

Locate in a Sorted Grid

EasyGridsPython, JavaScript, TypeScript, Java, C++

In grid, every row is sorted from left to right in non-decreasing order and every column is sorted from top to bottom in non-decreasing order. Return the position [row, col] of target. When target appears more than once, return the occurrence with the smallest row, and among those the one with the smallest column. When it does not appear at all, return [-1, -1].

Example 1

grid [[1,3,5],[2,4,8],[6,7,9]]
target 4
returns [1,1]

4 sits in row 1, column 1.

Example 2

grid [[1,3,5],[2,4,8],[6,7,9]]
target 10
returns [-1,-1]

10 is bigger than every cell.

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 Grids problems