Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3376 - Minimum Time to Break Locks I.

    Medium

    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.

    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 <code>i<sup>th</sup></code> 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:

    Input: strength = 3,4,1, K = 1

    Output: 4

    Explanation:

    The locks cannot be broken in less than 4 minutes; thus, the answer is 4.

    Example 2:

    Input: strength = 2,5,4, K = 2

    Output: 5

    Explanation:

    The locks cannot be broken in less than 5 minutes; thus, the answer is 5.

    Constraints:

    • n == strength.length

    • 1 &lt;= n &lt;= 8

    • 1 &lt;= K &lt;= 10

    • <code>1 <= strengthi<= 10<sup>6</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer findMinimumTime(List<Integer> strength, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait