Cracking the Safe

There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1].

The safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit.

Return any string of minimum length that will unlock the safe at some point of entering it.

Example 1
Inputn = 1, k = 2
Output"10"
The password is a single digit, so entering both digits unlocks the safe, and "01" would also work.
Example 2
Inputn = 2, k = 2
Output"01100"
The sequence contains every possible length-2 password over digits 0 and 1 as a substring, so it will unlock the safe.

Constraints

  • 1 <= n <= 4
  • 1 <= k <= 10
  • 1 <= k^n <= 4096

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate