Open the Lock
Signals to notice
Brute force first
DFS trying all combinations — doesn't find shortest path efficiently. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
The key insight
BFS on the state space: each state is a 4-digit string. From each state, generate 8 neighbors (each digit ±1). Skip deadends. The first time you reach the target is the shortest path. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
What must stay true
BFS guarantees shortest path. Each state has exactly 8 neighbors (4 digits × 2 directions). The state space is bounded at 10,000 possible combinations. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Easy way to go wrong
Not pre-loading deadends into the visited set — deadends should be marked as visited before BFS starts so they're never explored. The fix is usually to return to the meaning of each move, not just the steps themselves.