Write a program to find the shortest path in a grid with obstacles, optimizing for memory consumption.