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
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.