✅ C++ solution || Easy to understand.
{\n        int hours=0,p=0;\n        for(int i=0;i<energy.size();i++)\n        {\n            hours = energy[i] + hours; \n        }\n        hours = hours-init
{\n        int hours=0,p=0;\n        for(int i=0;i<energy.size();i++)\n        {\n            hours = energy[i] + hours; \n        }\n        hours = hours-initialEnergy+1;\n        if(hours<0)\n        {hours=0;}\n        while(p<energy.size())\n        {\n            if(initialExperience<=experience[p])\n            {\n                int diff=experience[p]-initialExperience+1;\n                hours += diff;\n                initialExperience+= diff;\n            }\n            initialExperience=initialExperience+experience[p];\n            p++;\n        }\n        return hours;\n    }
[]