← Questions

Shortest path through a required cell when revisits are free

0
Google DeepMindCodingLast asked Mar 2026

You get an N x M grid. Some cells are walls; the open cells include one start, one end and one checkpoint. You move up, down, left or right between open cells and may pass through a cell as often as you like, but a move only costs 1 when it enters a cell you have never visited before; going back over visited cells is free.

Find the cheapest walk from the start to the end that passes through the checkpoint on the way, or report that none exists. The interviewer wrapped it in a story; this is what it reduces to.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding