Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Stretch Problem: Open the Lock (medium)

This problem is optional. The problems above cover what the chapter teaches. This one is here for readers who want a harder queue question, and nothing later in the course depends on it.

Problem Statement

A lock has four wheels, and each wheel shows one digit from 0 to 9. A wheel can be turned one step in either direction, so 9 turns to 0 and 0 turns back to 9. Each single turn of a single wheel counts as one move.

The lock starts at "0000". Some settings are dead ends: if the lock ever shows one of them it stops working and cannot be turned again.

Given the array

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content