m × n grid of integers grid with this layout:
- every row is sorted in non-decreasing order;
- the first number of each row is greater than the last number of the row above.
In other words, writing the rows out one after another gives a sorted list.
Return True if value appears in the grid, otherwise False. Aim for O(log(m·n)).grid=[[2, 4, 4, 9], [12, 15, 18, 21], [30, 33, 40, 41]], value=18 → True
18 sits in the second row.
grid=[[2, 4, 4, 9], [12, 15, 18, 21], [30, 33, 40, 41]], value=10 → False
10 is above the end of the first row and below the start of the second, so it is nowhere.
grid=[[-7]], value=-7 → True
grid=[[2, 4, 4, 9], [12, 15, 18, 21], [30, 33, 40, 41]], value=18
True
Run checks the first 3 tests in your browser. Submit checks all 134 tests on the server, hidden ones included.