Question: Given a path in the form of a rectangular matrix having few landmines arbitrarily placed (marked as O), calculate the length of the shortest safe



Given a path in the form of a rectangular matrix having few landmines arbitrarily placed (marked as O), calculate the length of the shortest safe route possible from any cell in the first column to any cell in the last column of the matrix. We have to avoid landmines and their four adjacent cells (left, right, above and below) as they are also unsafe. We are allowed to move to only adjacent cells which are not landmines. i.e. the route cannot contain any diagonal moves. Print 'Not reachable' if there are no safe paths limport java.util.*; class Testclass \{ public static int findPath(int[][] matrix,boolean[][] possiblePath1) \{ //write your code here \} public static void prefillMap(int[][] matrix,boolean[][] possiblePath) \{ for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
