✅Easy C++ || Train and Fight || Clean, Fast and Friendly code || TC : O(n) SC : O(1)
The main idea here is to arrange the " if\'s " properly. The first \' if \' will check if we have enough Energy and Experience , we train accordingly and then w
The main idea here is to arrange the " **if\'s** " properly. The first \' if \' will check if we have enough **Energy** and **Experience** , we train accordingly and then we move on to fight the opponent.\nNext is losing energy and gaining experience after fighting every opponent.\n```\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {\n        int n = energy.size();     // since energy and experience arrays are of same size\n        int trainingHours = 0;\n        \n        for (int i = 0; i < n; ++i) {\n\t\t\t// TRAIN if needed\n            if (initialEnergy <= energy[i]) {\n                int difference = energy[i] - initialEnergy;\n                initialEnergy += difference + 1;\n                trainingHours += difference + 1;\n            }\n            if (initialExperience <= experience[i]) {\n                int difference = experience[i] - initialExperience;\n                initialExperience += difference + 1;\n                trainingHours += difference + 1;\n            }\n            \n\t\t\t// FIGHT because you got to!\n            initialEnergy -= energy[i];\n            initialExperience += experience[i];\n        }\n        return trainingHours;\n    }\n};
['C', 'C++']