Implement a system to find the shortest path in a dynamic grid with obstacles, optimizing for both time and memory.