Java Code with custom sort and comment
Sort the array with largest minumum-actual for each task, the top priority is the one with largest difference\nThen build up the minimum requirements by iterati
Sort the array with largest minumum-actual for each task, the top priority is the one with largest difference\nThen build up the minimum requirements by iterating the sorted array and add energy if the remaining is not enough for the next minimum\n\n    public int minimumEffort(int[][] tasks) {\n        \n        // Sort the array where with descending (minimum-actual), which is the order we process the tasks\n        Arrays.sort(tasks, new Comparator<int[]>(){\n            @Override\n            public int compare(int[] o1, int[] o2) {\n                if(o1[1]-o1[0] < o2[1]-o2[0]) return 1;\n                else if( o1[1]-o1[0] == o2[1]-o2[0]) return 0;\n                else return -1;\n            }\n        });\n\n        int current = 0;\n        int total = 0;\n        //considering the minumum requirements of the task\n        //current tracks the remaining energy left for the next tasks, need to increas if less than next minimum\n        for(int i=0;i<tasks.length;i++){\n            int[] node = tasks[i];\n            if(i==0){\n                total = node[1];\n                current = node[1]-node[0];\n            }\n            else{\n                if(current<node[1]){\n                    total+=node[1]-current;\n                    current = node[1]-node[0];\n                }\n                else{\n                    current -= node[0];\n                }\n            }\n            \n        }\n        \n        return total;\n    }
[]