m × n grid shop:
- 0 is a wall you cannot pass;
- 1 is an empty aisle;
- any other number is an item with that price; you can walk over item cells too.
You stand at start = [row, col], and each step moves you to a side-adjacent cell. You only care about reachable items whose price lies in price_range = [low, high], inclusive.
Items are ranked by the first criterion that differs:
1. shortest path length from the start, shorter is better;
2. price, cheaper is better;
3. row index, smaller is better;
4. column index, smaller is better.
Return the coordinates of the top count items in rank order, best first. If fewer items qualify, return all of them.shop=[[1, 4, 0], [3, 1, 2], [0, 6, 1]], price_range=[2, 4], start=[1, 1], count=2 → [[1, 2], [1, 0]]
All four neighbours of the start are one step away. The item priced 6 is out of range, leaving prices 2 at (1, 2), 3 at (1, 0) and 4 at (0, 1). At equal distance the cheaper item ranks higher, so the top two are [1, 2] and [1, 0].
shop=[[2, 0, 5], [1, 0, 1], [1, 1, 1]], price_range=[2, 5], start=[0, 0], count=3 → [[0, 0], [0, 2]]
The item on the start cell counts too, at distance 0. The item at (0, 2) is reached by going around the wall from below, 6 steps. Only two items qualify, so both are returned.
start lies inside the grid and is not a wallshop=[[1, 4, 0], [3, 1, 2], [0, 6, 1]], price_range=[2, 4], start=[1, 1], count=2
[[1, 2], [1, 0]]
Run checks the first 3 tests in your browser. Submit checks all 43 tests on the server, hidden ones included.