LeetCode 752 Open the Lock - Problem Statement

The problem

You have a lock with 4 wheels, each showing digits 0-9. Starting from "0000", find the minimum turns to reach the target.

Each turn rotates one wheel by one digit (9 wraps to 0, 0 wraps to 9).

Some combinations are "deadends" that lock you out permanently.

With deadends = ["0201","0101","0102","1212","2002"] and target = "0202":

  • "0000" → "1000" → "1100" → "1200" → "1201" → "1202" → "0202"
  • 6 moves. Answer: 6.

Constraints: Target ≠ "0000". Deadends don't include "0000".