A latency heatmap stores values in a grid grid where each row is sorted ascending from left to right and each column is sorted ascending from top to bottom. A row does not continue where the previous row ended, so the grid read row by row is not one sorted list.
Write inHeatmap(grid, target) that returns true if target is in the grid and false otherwise.
Use O(rows + cols) time.
Input: grid = [[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]], target = 9 Output: true
9 is at row 2, column 2.
Input: grid = [[1,4,7,11],[2,5,8,12],[3,6,9,16],[10,13,14,17]], target = 15 Output: false
15 would fall between values but is not in the grid.
1 <= rows, cols <= 300-10^9 <= grid[r][c], target <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #175 Value in a Sorted Heatmap. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.