Given a maze represented as a 2D grid where 0
represents an open cell and 1
represents a wall, determine the minimum number of steps required to move from the top-left corner (starting point) to the bottom-right corner (destination). You can only move horizontally or vertically (up, down, left, right).
If the destination is unreachable, return -1
.
Input:
maze = [
[0, 0, 1, 0],
[1, 0, 0, 0],
[0, 0, 1, 1],
[0, 1, 0, 0]
]
Output: 7
Hint: Use a Breadth-First Search (BFS) traversal to efficiently explore the maze.
Historical Note: On this day, as we reflect on computer science milestones, remember that simple graph traversal algorithms like BFS have powered many breakthroughs in both research and industry.