Skip to content

Practice Minimum Hours of Training to Win a Competition

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2383
LeetCode Problem

Minimum Hours of Training to Win a Competition

Problem Statement

You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively. You are also given two 0-indexed integer arrays energy and experience, both of length n. You will face n opponents in order. The energy and experience of the ith opponent is denoted by energy[i] and experience[i] respectively. When you face an opponent, you need to have both strictly greater experience and energy to defeat them and move to the next opponent if available. Defeating the ith opponent increases your experience by experience[i], but decreases your energy by energy[i]. Before starting the competition, you can train for some number of hours. After each hour of training, you can either choose to increase your initial experience by one, or increase your initial energy by one. Return the minimum number of training hours required to defeat all n opponents.

Source: Minimum Hours of Training to Win a Competition on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]
Output
8

# Example 2

Input
initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]
Output
0

Constraints

n == energy.length == experience.length
1 <= n <= 100
1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100

Related LeetCode Problems

Practice more problems similar to Minimum Hours of Training to Win a Competition.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.