I am working on below interview question and I am confuse on how to use BFS search here. I am confuse on how to deal with the blockades here?
Given a MxN matrix find the shortest path to reach a given destination cell. The robot can move up, down, left or right. The matrix also comes with set of blockades in few of the cells where the robot can't pass through. Output the minimum number of moves the robot needs to make to reach the destination. Output -1 if the destination is not reachable. Assume that the blockade will never be at the starting cell.
Input Format: First line contains the values of M and N matrix. Second line contains the cell location of the robots starting position. Third line contains the cell location of the destination. Fourth line and the lines following that will contain the locations of the blockades. The example below contains only one blockade at (2,2) where the robot can't pass through. Below is the input:
3 3
1 1
3 3
2 2
Output should be 4 for above input.
Below is what I have started but confuse on how to deal with blockades here while doing BFS search:
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int M = sc.nextInt();
int N = sc.nextInt();
int startX = sc.nextInt();
int startY = sc.nextInt();
int destinationX = sc.nextInt();
int destinationY = sc.nextInt();
while (sc.hasNext()) {
int blockedX = sc.nextInt();
int blockedY = sc.nextInt();
}
}