Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Could you determine the rank of every item efficiently?
We can perform a breadth-first search from the starting position and know the length of the shortest path from start to every item.
Sort all the items according to the conditions listed in the problem, and return the first k (or all if less than k exist) items as the answer.