Explanation on why sort by difference
Intuition\n\nSort by the difference mininum - actual and then process one by one.\n\nHow to come up with intuition\n\nObserve the examples.\nThe most important 
**Intuition**\n\nSort by the difference `mininum - actual` and then process one by one.\n\n**How to come up with intuition**\n\nObserve the examples.\nThe most important thing after receiving a problem is to understand it.\nHere understand means not only reading the text, but also going through the examples.\nOne can find the pattern by observing 3 examples that the minimum energy is achieved\nin an order of increasing difference.\n\n**Proof of why sort by difference**\n\n*Quick observation*: order matters. Just read example 1 again if you\'re not sure.\n\nSuppose we are given two tasks, `[a, a + c1]` and `[b, b + c2]`, where `c1 < c2` and `a, b` are two arbitrary numbers. We have two possible ordering:\nOrder 1: `[a, a + c1], [b, b + c2]`\nOrder 2: `[b, b + c2], [a, a + c1]`\n\nOrder 1 gives a result `[a + b, max(a + b + c1, b + c2)]`, and order 2 `[a + b, max(a + b + c2, a + c1)]`.\nLet `m1 = max(a + b+ c1, b + c2)`, `m2 = max(a + b + c2, a + c1)`. Since the final result depends \non `min(m1, m2)`, we should arrange in an order that results in a smaller minimum.\n\nWe want to prove that `[a, a + c1]` should always come first.\n1. Obviously, `a + b + c2 > a + c1` since `c2 > c1`.\n2. If `a + b + c1 >= b + c2`, i.e., `c1 < c2 <= c1 + a`, then we know `m1 = a + b + c1 <= a + b + c2 = m2`. So `[a, a + c1]` should come first.\n3. If `a + b + c1 < b + c2`, i.e., `c2 > a + c1 > c1`, then `m1 = b + c2 < a + b + c2 = m2`. Again, `[a, a + c1]` should come first.\n\nThis completes the proof for the case `c1 < c2`. The case `c1 > c2` can be proved similarly. The case `c1 == c2` is trivial.\n\nSo, in all cases,  `[a, a + c1]` should always come first.\n\n**Algorithm processing order vs actual task finish order**\n\nWe solve the problem in increasing difference order, while the actual tasks are finished in decreasing order. That\'s why we process in order `[a, a+c1], [b, b+c2]` but actually `[b, b+c2]` is finished first.\n\nIn other words, for a list of tasks `t1, t2, t3, ... tn`, we process in this order to get our solution, the minimum energy. But this minimum is achieved by finishing tasks in order `tn, ..., t2, t1`.\n\n**Code sample**\n```python\nclass Solution:\n    def minimumEffort(self, tasks: List[List[int]]) -> int:\n        tasks.sort(key=lambda t: t[1] - t[0])\n        res = [0, 0]\n        for t0, t1 in tasks:\n            res = [res[0] + t0, max(res[1]+t0, t1)]\n        return max(res)\n```
[]