Easy greedy java solution.
IntuitionOne needs to train just enough to haveApproachCalculate the sum of energy array. The hours need to train for gaining energy is going to be the differen
# Intuition
One needs to train just enough to have

# Approach
<!-- Describe your approach to solving the problem. -->
Calculate the sum of energy array. The hours need to train for gaining energy is going to be the difference between the total and initial energy.

Experience grows after every challenge, so only train if initialExperience <= experience[i]

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)

# Code
```java []
class Solution {
class Solution {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int hours = 0;
        int totalEnergy = 0;   
        for (int i = 0 ; i < experience.length; i++) {
            // calculate total energy
            totalEnergy += energy[i];
            // train to gain just enough experience to win the next challenge.
            if(initialExperience <= experience[i]) {
                    int temp = (experience[i] - initialExperience) + 1;
                    hours+=temp;
                    initialExperience+=temp;
            }
            // add experience after particapting in the challenge.
            initialExperience+=experience[i];
        }
        // train to gain just enough energy to win all the challenges.
        if(totalEnergy >= initialEnergy) {
            hours+= (totalEnergy - initialEnergy) + 1;
        }
        return hours;
    }
}
```
['Java']