Greedy after Sorting based on the difference !!
Approach: \n- We just need to sort the tasks vector based on the difference between the actual & minimum energy required in descending order.\n- Then we can tra
# Approach: \n- We just need to sort the `tasks` vector based on the difference between the actual & minimum energy required in descending order.\n- Then we can traverse the sorted array with `startEnergy` & `remEnergy` variables set to `0`.\n- We will keep adding the `diff` required to keep doing tasks. `GREEDY \uD83E\uDD11`\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(NlogN + N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minimumEffort(vector<vector<int>>& task) {\n        sort(task.begin(), task.end(), [](const vector<int>& a, const vector<int>& b) {\n            return (a[1] - a[0]) > (b[1] - b[0]);\n        });\n\n        int startEnergy = 0, remEnergy = 0;\n\n        for (const auto& t : task) {\n            if (remEnergy < t[1]) {\n                int diff = t[1] - remEnergy;\n                startEnergy += diff;\n                remEnergy += diff;\n            }\n            remEnergy -= t[0];\n        }\n        \n        return startEnergy;\n    }\n};\n```
['Greedy', 'Sorting', 'C++']