C++ O(N)/0ms 🚀 intuition solution with explanation 😎
There are three key things here\n1. strictly greater [most important]\n2. energy will be deducted always\n3. exp will gain\n\nBased on the first key, we need to
There are three key things here\n1. strictly greater [most important]\n2. energy will be deducted always\n3. exp will gain\n\nBased on the first key, we need to add additional 1 to guarantee `strictly greater`.\nBased on the second key, we know that our initialEnergy will always be exhausted. Therefore, it is intuitive to sum them up. BUT!!! We only add it up when our initialEnergy failed to exhaust the energy cost.\nLastly, this one is very straightforward in combat with the monster of the experience array. If exp[i] is great or equal to the initialExperience, we should add up the diff with an additional one. \nThat\'s all. Interesting question. Best.\n\n```cpp\nint minNumberOfHours(int initialEnergy, int ie, vector<int>& energy, vector<int>& exp) {\n  int ans = 0, su=-initialEnergy+1;\n  for (auto n: energy) su+=n;\n  ans += su>0?su:0;\n\n  for (int i=0;i<exp.size()&&ie<100;i++) {\n\tif (exp[i]>=ie) {\n\t  ans+=exp[i]-ie+1;\n\t  ie=exp[i]+1;\n\t}\n\tie+=exp[i];\n  }\n  return ans;\n}\n```
['C']