Ctrl K

Duels With Growing Energy

Hard
You have to beat every opponent; the i-th opponent has strength strength[i]. You start with 0 energy and an energy gain of 1. Each day your energy grows by the current gain. After that, if your energy is at least the strength of some opponent you have not beaten yet, you may beat them (at most one opponent per day). After a win your energy drops to 0 and your gain goes up by 1. Opponents can be beaten in any order. Return the fewest days needed to beat them all.
Example 1
strength=[5, 2] → 5

Days 1–2: energy 1 + 1 = 2, beat the opponent of strength 2. The gain becomes 2: days 3–5 give 2 + 2 + 2 = 6 ≥ 5. That is 5 days. Starting with the stronger one takes 5 + 1 = 6 days.

Example 2
strength=[6, 6, 6] → 11

With gains of 1, 2 and 3 it takes 6, 3 and 2 days: 11 in total.

Example 3
strength=[1, 10] → 6

Beat the weak one on day 1, then five days of 2 energy each for the strong one: 6.

Constraints
  • 1 ≤ len(strength) ≤ 17
  • 1 ≤ strength[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSettle Up in the Fewest Transfers HardTwo Groups With the Same Average HardAssembling Fragments HardSquare-Sum Chains HardSmallest Team With Every Skill Hard
loading Python…
Input
strength=[5, 2]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.