Skip to content

Practice K Highest Ranked Items Within a Price Range

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2146
LeetCode Problem

K Highest Ranked Items Within a Price Range

Problem Statement

In grid, 0 is an impassable wall, 1 is a passable empty cell, and values greater than 1 are passable item cells whose values are prices. Starting at start = [row,col], move between side-adjacent passable cells at one step per move. Return coordinates of up to k reachable items priced within pricing = [low,high] inclusive, ordered by shortest distance, then price, then row, then column, all ascending.

Source: K Highest Ranked Items Within a Price Range on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3
Output
[[0,1],[1,1],[2,1]]

# Example 2

Input
grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2
Output
[[2,1],[1,2]]

# Example 3

Input
grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3
Output
[[2,1],[2,0]]

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 10^5
1 <= m * n <= 10^5
0 <= grid[i][j] <= 10^5
pricing.length == 2
2 <= low <= high <= 10^5
start.length == 2
0 <= row <= m - 1
0 <= col <= n - 1
grid[row][col] > 0
1 <= k <= m * n

Related LeetCode Problems

Practice more problems similar to K Highest Ranked Items Within a Price Range.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.