dsa1 min read
Keys and Rooms — DFS/BFS Graph Reachability
Determine if all rooms are reachable. Start from room 0, DFS using keys found in each room to unlock new rooms.
Read →
webcoderspeed.com
1276 articles
Determine if all rooms are reachable. Start from room 0, DFS using keys found in each room to unlock new rooms.
Check if a path exists between source and destination in an undirected graph. BFS from source or Union-Find both work in O(V+E).
BFS from entrance in a maze to find nearest exit (border empty cell). Classic BFS shortest path with exit condition.
Minimum dice rolls to reach square n^2. Convert board position to 2D coordinates (Boustrophedon order), BFS on board states.
Minimum turns to reach target combination avoiding deadends. BFS over all 4-digit wheel states with bidirectional BFS optimization.