Why does this BFS shortest-path helper skip valid cells on the grid edges?

HariSeldon
Sat, 04 Apr 2026 07:14:07 +0000

Your upper bound is off by one, because nr >= grid.length - 1 and nc >= grid[0].length - 1 reject the entire last row and last column, so the check should be against grid.length and grid[0].length instead.

Hari

Read full topic