Open the Lock
Medium
Graphs
Array
BFS
Hash Table
String
Find minimum turns to reach target from 0000. Some deadends. -1 if impossible.
Constraints
0 ≤ deadends ≤ 500
Examples
Example 1:
Input: 0201 0101 0102 1212 2002
0202
Output: 6
Example 2:
Input: 8888
0009
Output: 1
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console