C++ greedy O(n) Runtime with O(n) space and easy to understand with explanation
Intution here is we need to work on the tasks whose difference of enery to begin and energy to complete in decreasing order which allows us to spend enery more 
* **Intution** here is we need to work on the tasks whose difference of enery to begin and energy to complete in decreasing order which allows us to spend enery more efficiently.\n* **Algorithm:**\n\t1. Lets first calculate total energy required to finish all the tasks ie. tasks[0][0]+tasks[1][0]+...+tasks[n-1][0]\n\t2. now lets find minimum of tasks[i][1]-tasks[i][0] i.e minimum amount of extra energy required to begin all the tasks \n\t3. Our final answer will be maximum of total_energy_required+min_diff_begin_needed and maximum of energy_required_to_begin\n```\nclass Solution {\npublic:\n    int minimumEffort(vector<vector<int>>& tasks) {\n        int n = tasks.size();\n        int min_diff_begin_needed = INT_MAX,max_energy_required_to_begin = INT_MIN;\n        int total_energy_required = 0;\n        for(int i =0;i<n;i++){\n            total_energy_required += tasks[i][0];\n            min_diff_begin_needed = min(min_diff_begin_needed,tasks[i][1]-tasks[i][0]);\n            max_energy_required_to_begin = max(max_energy_required_to_begin,tasks[i][1]);\n        }\n        return (total_energy_required + min_diff_begin_needed) > max_energy_required_to_begin ? (total_energy_required + min_diff_begin_needed) : max_energy_required_to_begin;\n    }\n};\n```
['Greedy', 'C']