✅✅Faster || Easy To Understand || C++ Code
Time Complexity :- O(N)\n\n Space Complexity :- O(1)*\n\n\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<
* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {\n        \n        int n = energy.size();\n        \n        int total_energy = 0;\n        \n        for(int i = 0; i < n; i++)\n        {\n            total_energy += energy[i];\n        }\n        \n        // cal. the exercise req for get sufficient energy\n        \n        int exercise_for_energy = 0;\n        \n        if(initialEnergy <= total_energy)\n        {\n            exercise_for_energy += total_energy + 1 - initialEnergy;\n        }\n        \n        // cal. the exercise req for get sufficient experience\n        \n        int exercise_for_experience = 0;\n        \n        int curr_experience = initialExperience;\n        \n        for(int i = 0; i < n; i++)\n        {\n            if(curr_experience > experience[i])\n            {\n                curr_experience += experience[i];\n            }\n            else\n            {\n                int req_experience = experience[i] + 1 - curr_experience;\n                \n                exercise_for_experience += req_experience;\n                \n                curr_experience +=  req_experience + experience[i];\n            }\n        }\n    \n        return exercise_for_energy + exercise_for_experience;\n    }\n};\n```
['C', 'C++']