Open the Lock Problem
Open the Lock Problem — ExecCode Medium DSA Practice
Solve the Open the Lock problem on ExecCode. Free online medium DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You have a lock with 4 dialed wheels (0000–9999). Given a list of deadends and a target, return the minimum total number of turns required to open the lock, or -1 if impossible.
Examples
Input deadends = ["0201", "0101", "0102", "1212", "2002"], target = "0202"; Output 6. Input deadends = ["8888"], target = "0009"; Output 1. Input deadends = [], target = "0000"; Output 0
Constraints
1 ≤ deadends.length ≤ 500 deadends[i].length == target.length == 4 target will not be in deadends in the walkthrough
Practice Open the Lock free on ExecCode. Browse DSA problems, topic map, and placement guides.