GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesCombination Dial Lock

Gamified challenge · Breadth-first search

Combination Dial Lock

A lock has four wheels, each showing a digit 0–9, and starts at "0000". One turn moves one wheel one notch up or down, and the wheels wrap round (9 up is 0, 0 down is 9). Every combination in deadends jams the lock: it may never be shown, not even for a moment.

Write openLock(deadends, target) that returns the fewest turns to show target, or -1 if it can't be done (for example when 0000 or the target is itself a jam). If target is "0000", the answer is 0.

Example: with deadends = ["8888"] and target = "0009", turn the last wheel down once: the answer is 1.

Sign in to play Combination Dial Lock

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account