Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think of using breadth-first search.
Use a BFS to find for each cell the time at which it will become flooded.
Another BFS then simulates your movement, taking into account information gathered by the first BFS.