LeetCode solutions

2459. Minimum Hours of Training to Win a Competition

My accepted Python solution to LeetCode problem 2459, Minimum Hours of Training to Win a Competition, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.5MB, accepted 2026-01-01.

python
class Solution:
    def minNumberOfHours(self, initialEnergy: int, initialExperience: int, energy: List[int], experience: List[int]) -> int:
        hours = 0
        # For energy, we need strictly greater than sum of all opponent energies
        total_energy = sum(energy)
        if initialEnergy <= total_energy:
            hours += total_energy - initialEnergy + 1
        
        # For experience, simulate each opponent
        curr_exp = initialExperience
        for exp in experience:
            if curr_exp <= exp:
                hours += exp - curr_exp + 1
                curr_exp = exp + 1
            curr_exp += exp
        
        return hours

Source