Given a 2D matrix consisting of 'o’s and ‘x’, we need to calculate the shortest path to reach from any x in the first row to any x in the last row. It is possible to travel in all 8 directions. There may be more than one number of x’s in the first and last row. Print -1 if it’s not possible to reach any of the x’s in the last row.
1<row<1000
1<column<1000
eg. o o x
x x o
x o o
O/P- 2
How to approach this problem?