Amazon | 2nd round(video call) | Mario needs to Rescue Peach inside a castle of Lava

I gave interview in Amazon for SDE 2 role. In the 2nd round I was this question. Interview was on video call:-
Goal : Mario needs to Rescue Peach inside a castle of Lava.
Facts :

  1. The castle is filled with lava. There are some landing spots that are safe.
  2. Each landing spot is defined by an x-index and a y-index in a grid.
  3. Mario always start at landing spot (0,0) at the entrance to the lava castle.
  4. The distance between landing spots are defined as the square root of the sum of
    the squares of x-index and y-index difference.
  5. Mario can only safely jump a distance of 5 units.
  6. Calculate the minimum number of jumps Mario needs to reach Peach and rescue her.

Examples :
Peach at (3,3) , safe spots (1,1), (2,2) → 1 jump (0,0) - (3,3)
Peach at (5,5), safe spots (1,1), (2,2), (3,3), (4,4) → 2 jumps (0,0) - (3,3) - (5,5)
Peach at (10, 0) safe spots (0,4), (0, 5), (5,5), (10,5) → 4 jumps
Peach at (5,5) safe spots (0,1), (1,0), (1,1) → -1 (cannot rescue Peach)

public class Spot {
    public int x;   // x index 
    public int y;   // y index
}

public interface Map{
    public Spot getPeachSpot();
    public List<Spot> getSafeSpots();
}

public int calculateMinimumJumps(final Map map) {
// code here

}

I am not able to solve this correctly. I tried using DFS. Please suggest solution

Comments (2)