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
Input
n = 1, k = 2Output
"10"The password is a single digit, so entering both digits unlocks the safe, and "01" would also work.
Example 2
Input
n = 2, k = 2Output
"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