Dsa
Graphs Bfs
Medium
River Crossing
In a valley, there are multiple rivers represented as a grid. Each river can either be dry (0) or wet (1). A person can move to an adjacent cell (horizontally or vertically) if the cell is a dry river (0). Determine the minimum number of moves needed to cross from the leftmost column to the rightmost column of the grid. If it's impossible to cross, return -1. Input consists of an integer m (number of rows) and an integer n (number of columns) followed by m lines of n integers representing the grid. Example input: 4 5 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 1 | Output: 7
Key concepts
graphsbfswater
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now