You're tasked with cracking a digital safe that has a unique password verification system. The safe requires a password consisting of n consecutive digits, where each digit can range from 0 to k-1.
Here's the catch: the safe doesn't reset between attempts. Instead, it continuously monitors the last n digits you've entered. Every time you input a new digit, the safe checks if the most recent n digits match the correct password.
Example: If the password is "345" (n=3) and you enter "012345":
- After typing
0: recent digits ="0"❌ - After typing
1: recent digits ="01"❌ - After typing
2: recent digits ="012"❌ - After typing
3: recent digits ="123"❌ - After typing
4: recent digits ="234"❌ - After typing
5: recent digits ="345"✅ Safe unlocked!
Goal: Find the shortest possible string that is guaranteed to unlock the safe, regardless of what the actual password is. This string must contain every possible n-digit combination as a substring.
Input & Output
Visualization
Time & Space Complexity
Visit each of the k^n edges exactly once in DFS
Store visited edges and recursion stack
Constraints
- 1 ≤ n ≤ 4
- 1 ≤ k ≤ 10
- 1 ≤ kn ≤ 4096
- The answer is guaranteed to exist and be unique