Implement an algorithm to find the shortest path on a 2D grid containing dynamic obstacles, optimizing for both time complexity and memory usage.