|
| 1 | +3376\. Minimum Time to Break Locks I |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +Bob is stuck in a dungeon and must break `n` locks, each requiring some amount of **energy** to break. The required energy for each lock is stored in an array called `strength` where `strength[i]` indicates the energy needed to break the <code>i<sup>th</sup></code> lock. |
| 6 | + |
| 7 | +To break a lock, Bob uses a sword with the following characteristics: |
| 8 | + |
| 9 | +* The initial energy of the sword is 0. |
| 10 | +* The initial factor `X` by which the energy of the sword increases is 1. |
| 11 | +* Every minute, the energy of the sword increases by the current factor `X`. |
| 12 | +* To break the <code>i<sup>th</sup></code> lock, the energy of the sword must reach **at least** `strength[i]`. |
| 13 | +* After breaking a lock, the energy of the sword resets to 0, and the factor `X` increases by a given value `K`. |
| 14 | + |
| 15 | +Your task is to determine the **minimum** time in minutes required for Bob to break all `n` locks and escape the dungeon. |
| 16 | + |
| 17 | +Return the **minimum** time required for Bob to break all `n` locks. |
| 18 | + |
| 19 | +**Example 1:** |
| 20 | + |
| 21 | +**Input:** strength = [3,4,1], K = 1 |
| 22 | + |
| 23 | +**Output:** 4 |
| 24 | + |
| 25 | +**Explanation:** |
| 26 | + |
| 27 | +| Time | Energy | X | Action | Updated X | |
| 28 | +|------|--------|---|----------------------|-----------| |
| 29 | +| 0 | 0 | 1 | Nothing | 1 | |
| 30 | +| 1 | 1 | 1 | Break 3rd Lock | 2 | |
| 31 | +| 2 | 2 | 2 | Nothing | 2 | |
| 32 | +| 3 | 4 | 2 | Break 2nd Lock | 3 | |
| 33 | +| 4 | 3 | 3 | Break 1st Lock | 3 | |
| 34 | + |
| 35 | +The locks cannot be broken in less than 4 minutes; thus, the answer is 4. |
| 36 | + |
| 37 | +**Example 2:** |
| 38 | + |
| 39 | +**Input:** strength = [2,5,4], K = 2 |
| 40 | + |
| 41 | +**Output:** 5 |
| 42 | + |
| 43 | +**Explanation:** |
| 44 | + |
| 45 | +| Time | Energy | X | Action | Updated X | |
| 46 | +|------|--------|---|----------------------|-----------| |
| 47 | +| 0 | 0 | 1 | Nothing | 1 | |
| 48 | +| 1 | 1 | 1 | Nothing | 1 | |
| 49 | +| 2 | 2 | 1 | Break 1st Lock | 3 | |
| 50 | +| 3 | 3 | 3 | Nothing | 3 | |
| 51 | +| 4 | 6 | 3 | Break 2nd Lock | 5 | |
| 52 | +| 5 | 5 | 5 | Break 3rd Lock | 7 | |
| 53 | + |
| 54 | +The locks cannot be broken in less than 5 minutes; thus, the answer is 5. |
| 55 | + |
| 56 | +**Constraints:** |
| 57 | + |
| 58 | +* `n == strength.length` |
| 59 | +* `1 <= n <= 8` |
| 60 | +* `1 <= K <= 10` |
| 61 | +* <code>1 <= strength[i] <= 10<sup>6</sup></code> |
0 commit comments