Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Open the Lock
Bookmark
Input
Simple: target 0009 (1 turn)
Quick: target 0001 (1 turn)
Blocked: some neighbors dead
Impossible: start boxed in
Custom
deadends
=
[8888]
,
target
=
0009
queue
queue
0000
9000
1000
0900
0100
9000
1000
0900
0100
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
1000
0900
0100
0090
0010
0009
0001
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
0080
0099
0091
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
0080
0099
0091
front
rear
queue
0000
9000
1000
0900
0100
0090
0010
0009
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
0080
0099
0091
0020
0019
0011
0001
8000
9900
9100
9090
9010
9009
9001
2000
1900
1100
1090
1010
1009
1001
0800
0990
0910
0909
0901
0200
0190
0110
0109
0101
0080
0099
0091
0020
0019
0011
front
rear
queue
algo
master
.
io
Step:
Start: Find minimum turns to open the lock using BFS
0 / 115
Input
Simple: target 0009 (1 turn)
Quick: target 0001 (1 turn)
Blocked: some neighbors dead
Impossible: start boxed in
Custom
deadends
=
[8888]
,
target
=
0009
0 / 115
algo
master
.
io
Step:
Start: Find minimum turns to open the lock using BFS