Two Java O(n) Solutions with Explanation, min array and stack
If we know the smallest element at the right hand side and the current largest element, we can create a new chunk if largest element <= smallest element at the 
If we know the smallest element at the right hand side and the current largest element, we can create a new chunk if largest element <= smallest element at the right hand side. The smallest element at the right hand side can be tracked by either an array or stack. The last element will always create a new chunk, either itself (if it\'s the largest one) or combine with the previous elements.\n\n```\n    public int maxChunksToSorted(int[] arr) {\n        int n = arr.length;\n        Stack<Integer> smallest = new Stack<Integer>();\n        for (int i = n-1; i >= 0; i--) {\n            if (smallest.isEmpty() || arr[i] <= smallest.peek())\n                smallest.push(arr[i]);\n        }\n        int largest = arr[0];\n        int ret = 0;\n        for (int i = 0; i < n-1; i++) {\n            if (arr[i] == smallest.peek())\n                smallest.pop();\n            largest = Math.max(largest, arr[i]);\n            if (largest <= smallest.peek()) {\n                ret++;\n                largest = arr[i+1];\n            }\n        }\n        return ret+1;\n    }\n\n    public int maxChunksToSorted(int[] arr) {\n        int n = arr.length;\n        int[] smallest = new int[n];\n        smallest[n-1] = arr[n-1];\n        for (int i = n-2; i >= 0; i--) {\n            smallest[i] = Math.min(smallest[i+1], arr[i]);\n        }\n        int largest = arr[0];\n        int ret = 0;\n        for (int i = 0; i < n-1; i++) {\n            largest = Math.max(largest, arr[i]);\n            if (largest <= smallest[i+1]) {\n                ret++;\n                largest = arr[i+1];\n            }\n        }\n        return ret+1;\n    }\n```
[]