Tap here to switch tabs
Problem
Submissions
Solution

Solution: Open the Lock

Statement

Time complexity

  1. Building nextSlot and prevSlot maps, each mapping every digit to one neighbor. Each map has nn key–value pairs. So, the total time it takes: O(n)O(n).

  2. Inserting all dd deadend combinations of length ww into a hash set will cost: O(dw)O(d · w).

  3. BFS over the state space:

    1. Total possible combinations of the lock:

                                                                        states=nw\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\s ...

Tap here to switch tabs
Problem
Submissions
Solution

Solution: Open the Lock

Statement

Time complexity

  1. Building nextSlot and prevSlot maps, each mapping every digit to one neighbor. Each map has nn key–value pairs. So, the total time it takes: O(n)O(n).

  2. Inserting all dd deadend combinations of length ww into a hash set will cost: O(dw)O(d · w).

  3. BFS over the state space:

    1. Total possible combinations of the lock:

                                                                        states=nw\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\s ...