Basic Practice - Linear Traversal | Python
1- Code\n\nclass Solution:\n    def minNumberOfHours(self, initialEnergy: int, initialExperience: int, energy: List[int], experience: List[int]) -> int:\n      
1- Code\n```\nclass Solution:\n    def minNumberOfHours(self, initialEnergy: int, initialExperience: int, energy: List[int], experience: List[int]) -> int:\n        \n        res = 0\n        cur_eng, cur_epe = initialEnergy, initialExperience\n        \n        for E, e in zip(energy, experience):\n            if cur_eng < E + 1:\n                res += E + 1 - cur_eng\n                cur_eng = E + 1\n            if cur_epe < e + 1:\n                res += e + 1 - cur_epe\n                cur_epe = e + 1\n            cur_eng, cur_epe = cur_eng - E, cur_epe + e\n        \n        return res\n```\n\n2- Video Explanation: [Click Here](https://youtu.be/JaE7uegBikY;)\n\n3- Analysis\n\n"""\nMethod: linear traversal\n\nIdea:\n\n- During the linear traversal, we check the cur_energy and cur_experience\nwith the opponent_energy, opponent_experience\n\n- If the cur_engery > opponent_energy and cur_experience > oppenent_experience,\nno training is needed.\n- Else:\n  the training hours needed are:\n       if cur_energy < opponent_enery:  \n          opponent_energy + 1 - cur_energy\n          We can reset the cur_energy = opponent_energy + 1 after traning\n       if cur_experience < opponent_experience:\n          opponent_experience + 1 - cur_experience\n          We can reset the cur_experience = opponent_experience + 1 after traning\n\n  As we have done the reset, after beating current opponent, the energy and experience\n  before meeting next opponent are:\n        cur_energy - current opponent_energy\n        cur_experience + current opponent_experience.\n        \n        \nWalkthrough\n\ninitialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]\n\nBefore beat opponent 0: cur_energy 5, cur_epe 3, res: 0\nAfter beat opponent 0: cur_energy 4, cur_epe 5, res: 0\n\nBefore beat opponent 1: cur_energy 4, cur_epe 5, res: 0\nAfter beat opponent 1: cur_energy 1, cur_epe 13, res: 3\n\nBefore beat opponent 2: cur_energy 1, cur_epe 13, res: 3\nAfter beat opponent 2: cur_energy 1, cur_epe 16, res: 6\n\nBefore beat opponent 3: cur_energy 1, cur_epe 16, res: 6\nAfter beat opponent 3: cur_energy 1, cur_epe 17, res: 8\n    \n"""
['Python']