3 liner using parallel Sort, parallel Prefix and parallel Stream. Fastest for huge arrays.
Intuition\nSort the array by difference between required minimum and consumptuon.\n\n# Approach\nFind the cumulative sum for total consumption with parallelPref
# Intuition\nSort the array by difference between required minimum and consumptuon.\n\n# Approach\nFind the cumulative sum for total consumption with parallelPrefix function. After that check the maximum difference between the current cumullative consumption and minumum required energy and add that to the total consumptuon.\n\n# Complexity\n- Time complexity:\n$$O(n \\cdot log(n))$$ - for sorting\n\n- Space complexity:\n$$O(1)$$ - we use original array so no extra space\n\n# Code\n```\nclass Solution {\n    public int minimumEffort(int[][] tasks) {\n        Arrays.parallelSort(tasks, (a, b)-> Integer.compare(a[1]-a[0], b[1]-b[0]));\n        Arrays.parallelPrefix(tasks, (a, b) -> {int[] c = new int[2]; c[0]= b[0]+a[0]; c[1] = b[1]; return c;});\n        return tasks[tasks.length-1][0] + Arrays.stream(tasks).parallel().mapToInt(t-> t[1]-t[0]).max().getAsInt();\n    }\n}\n```
['Java']