|
11 | 11 |
|
12 | 12 | ## 753. Cracking the Safe (Hard)
|
13 | 13 |
|
14 | | -<p> |
15 | | -There is a box protected by a password. The password is <code>n</code> digits, where each letter can be one of the first <code>k</code> digits <code>0, 1, ..., k-1</code>. |
16 | | -</p><p> |
17 | | -You can keep inputting the password, the password will automatically be matched against the last <code>n</code> digits entered. |
18 | | -</p><p> |
19 | | -For example, assuming the password is <code>"345"</code>, I can open it when I type <code>"012345"</code>, but I enter a total of 6 digits. |
20 | | -</p><p> |
21 | | -Please return any string of minimum length that is guaranteed to open the box after the entire string is inputted. |
22 | | -</p> |
23 | | - |
24 | | -<p><b>Example 1:</b><br /> |
| 14 | +<p>There is a box protected by a password. The password is a sequence of <code>n</code> digits where each digit can be one of the first <code>k</code> digits <code>0, 1, ..., k-1</code>.</p> |
| 15 | + |
| 16 | +<p>While entering a password, the last <code>n</code> digits entered will automatically be matched against the correct password.</p> |
| 17 | + |
| 18 | +<p>For example, assuming the correct password is <code>"345"</code>, if you type <code>"012345"</code>, the box will open because the correct password matches the suffix of the entered password.</p> |
| 19 | + |
| 20 | +<p>Return any password of <strong>minimum length</strong> that is guaranteed to open the box at some point of entering it.</p> |
| 21 | + |
| 22 | +<p> </p> |
| 23 | + |
| 24 | +<p><b>Example 1:</b></p> |
| 25 | + |
25 | 26 | <pre>
|
26 | 27 | <b>Input:</b> n = 1, k = 2
|
27 | | -<b>Output:</b> "01" |
28 | | -<b>Note:</b> "10" will be accepted too. |
| 28 | +<b>Output:</b> "01" |
| 29 | +<b>Note:</b> "10" will be accepted too. |
29 | 30 | </pre>
|
30 | | -</p> |
31 | 31 |
|
32 | | -<p><b>Example 2:</b><br /> |
| 32 | +<p><b>Example 2:</b></p> |
| 33 | + |
33 | 34 | <pre>
|
34 | 35 | <b>Input:</b> n = 2, k = 2
|
35 | | -<b>Output:</b> "00110" |
36 | | -<b>Note:</b> "01100", "10011", "11001" will be accepted too. |
| 36 | +<b>Output:</b> "00110" |
| 37 | +<b>Note:</b> "01100", "10011", "11001" will be accepted too. |
37 | 38 | </pre>
|
38 | | -</p> |
39 | 39 |
|
40 | | -<p><b>Note:</b><br> |
| 40 | +<p> </p> |
| 41 | + |
| 42 | +<p><b>Note:</b></p> |
| 43 | + |
41 | 44 | <ol>
|
42 | | -<li><code>n</code> will be in the range <code>[1, 4]</code>.</li> |
43 | | -<li><code>k</code> will be in the range <code>[1, 10]</code>.</li> |
44 | | -<li><code>k^n</code> will be at most <code>4096</code>.</li> |
| 45 | +<li><code>n</code> will be in the range <code>[1, 4]</code>.</li> |
| 46 | +<li><code>k</code> will be in the range <code>[1, 10]</code>.</li> |
| 47 | +<li><code>k^n</code> will be at most <code>4096</code>.</li> |
45 | 48 | </ol>
|
46 | | -</p> |
| 49 | + |
| 50 | +<p> </p> |
47 | 51 |
|
48 | 52 | ### Related Topics
|
49 | 53 | [[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
|
|
0 commit comments