Fewest Dial Turns to Open a Locker While Avoiding Locked Codes
Last updated: November 29, 2026
Quick Overview
A four-wheel combination dial starts at 0000, and each turn rotates one wheel up or down by one digit with wraparound. Given codes that freeze the dial and a target code, return the fewest turns to reach the target, or -1.
Meta
November 29, 20260
0
0 solved
A four-wheel combination dial starts at 0000, and each turn rotates one wheel up or down by one digit with wraparound. Given codes that freeze the dial and a target code, return the fewest turns to reach the target, or -1.
A Meta phone screen classic for implicit graph BFS, framed as lockers in a Meta office. Interviewers check whether you see the 10,000 states as nodes, generate neighbors cleanly, and treat blocked codes correctly including the start.
What the Interviewer Expects
- Treat each 4-digit code as a node with 8 neighbors
- Use BFS because every turn costs one
- Handle a blocked start code
- Handle modular wraparound on each wheel
- Mention bidirectional BFS for speed
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Implement bidirectional BFS and estimate the speedup.
- What if the dial had 6 wheels?
- Can you compute the answer directly when no codes are blocked?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Codes are 4-character digit strings, the blocklist has up to 500 entries.
- Return the minimum turns from
0000totarget, avoiding blocked codes....
High-Level Design
The state space is the 10^4 codes. From each code, change one wheel by plus or minus one, giving 8 neighbors. BFS from 0000 with blocked codes pre-marked as unusable gives the minimum turns. Bidirec...