A pricing heatmap is an n × n grid grid where every row is sorted ascending from left to right and every column is sorted ascending from top to bottom. Values can repeat.
Write kthInGrid(grid, k) that returns the k-th smallest value in the whole grid, counting repeats (so k = 1 is the smallest value).
Try to beat sorting all n² values.
Input: grid = [[1,5,9],[10,11,13],[12,13,15]], k = 8 Output: 13
In order: 1, 5, 9, 10, 11, 12, 13, 13, 15. The 8th is 13.
Input: grid = [[-5]], k = 1 Output: -5
A single cell is the only value.
1 <= n <= 3001 <= k <= n²-10^9 <= grid[r][c] <= 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 #174 Kth Smallest 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.