Minimum Time to Break Locks I

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 i^th lock.

To break a lock, Bob uses a sword with the following characteristics:

  • The initial energy of the sword is 0.
  • The initial factor x by which the energy of the sword increases is 1.
  • Every minute, the energy of the sword increases by the current factor x.
  • To break the i^th lock, the energy of the sword must reach at least strength[i].
  • After breaking a lock, the energy of the sword resets to 0, and the factor x increases by a given value k.

Your task is to determine the minimum time in minutes required for Bob to break all n locks and escape the dungeon.

Return the minimum time required for Bob to break all n locks.

Example 1
Inputstrength = [3,4,1], k = 1
Output4
The locks cannot be broken in less than 4 minutes; thus, the answer is 4.
Example 2
Inputstrength = [2,5,4], k = 2
Output5
The locks cannot be broken in less than 5 minutes; thus, the answer is 5.

Constraints

  • n == strength.length
  • 1 <= n <= 8
  • 1 <= k <= 10
  • 1 <= strength[i] <= 10^6

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