Java Solution | Binary search | Sorting
Sort the array according to diffference between minimun energy and actual energy(In descending order)\n2. Calculate the sum of actual energy and sum of minimum 
1. Sort the array according to diffference between minimun energy and actual energy(In descending order)\n2. Calculate the sum of actual energy and sum of minimum energy i.e sum of tasks[i][0] and tasks[i][1]\n3. we know that our answer lies between these two sum, we can use binary search to find the answer, if mid is the correct answer then we need to minimize these, so we will move to left.\n4. To check the answer, check if num is less than tasks[i][1] then decrease num by tasks[i][0] otherwise return false. If we reach to the end of tasks we can say that we found the answer\n\n**Time complexity**: O(nlogn) + O(nlogn)\n**Space complexity**: O(1)\n\n```\nclass Solution {\n    public int minimumEffort(int[][] tasks) {\n        int start = 0;\n        int end = 0;\n        for(int[] task: tasks){\n            start += task[0];\n            end += task[1];\n        }\n        int res = Integer.MAX_VALUE;\n        Arrays.sort(tasks, (a, b) -> { return (b[1] - b[0]) - (a[1] - a[0]);});\n        System.out.println(Arrays.deepToString(tasks));\n        while(start<=end){\n            int mid = start + (end-start)/2;\n            if(isValid(tasks, mid)){\n                res = Math.min(res,mid);\n                end = mid-1;\n            }else{\n                start = mid+1;\n            }\n        }\n        return res;\n    }\n    boolean isValid(int[][] tasks, int num){\n        for(int[] task: tasks){\n            if(num<task[1]){\n                return false;\n            }\n            num -= task[0];\n        }\n        return true;\n    }\n}
['Sorting', 'Binary Tree', 'Java']