100Days of Code #Day 2

  • All the visited cells of the path are 0.
  • All the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).
Input: grid = [[0,1],[1,0]]
Output: 2
  1. The starting and ending element must not be 1 so ensuring the edge cases starting from the initial index
  2. Check all its possible neighbors (in all directions) if any of them is zero add it to the queue and increase the index’s distance by one.
  3. return upon arriving at the destination.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store