Now, of course, the BFS algorithm needs to be modified so that it can be applied to the binary grid in the problem. The core approach for traversal is still the same, by adding and removing grid cells (instead of tree nodes) into the queue. To make our task easier, let's first consider some invalid cases.
- If we have a grid that has the top-left element as 1, then there will be no clear path (cannot start the path from 1).
- If a grid has the bottom-right element as 1, then there will be no clear path (cannot end the path).
