Snapchat | Phone Screen | Senior SDE
Anonymous User
1540

Given a mxn Binary matrix print the shortest path from start to end. Start can be any point in the first row and end can be any point in the last row. The land value is denoted by 1 and water is 0. You can move only in 4 directions. Update the matrix to print contain the shortest path only.

Example
Input :
{ [ '1', '0', '0', '1', '0' ],
[ '1', '0', '1', '1', '0' ],
[ '0', '1', '1', '0', '0' ],
['0', '1', '1', '0', '0' ] }

Output :
{ [ '0', '0', '0', '1', '0' ],
[ '0', '0', '1', '1', '0' ],
[ '0', '0', '1', '0', '0' ],
['0', '0', '1', '0', '0' ] }

Comments (8)