1665. Minimum Initial Energy to Finish Tasks
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def minimumEffort(self, tasks: List[List[int]]) -> int:
        tasks.sort(key=lambda x: x[1] - x[0], reverse=True)
        total_effort = 0
        current_energy = 0
        for effort, minimum in tasks:
            if current_energy < minimum:
                total_effort += minimum - current_energy
                current_energy = minimum
            current_energy -= effort
        return total_effort

```
['Python3']