JAVA || 0 ms || full explanation using comments || faster than 100% submission || O(n) time
\nclass Solution {\n    public int maxChunksToSorted(int[] arr) {\n        int[] leftMax=new int[arr.length];    // this array stores the max value from 0 to it
```\nclass Solution {\n    public int maxChunksToSorted(int[] arr) {\n        int[] leftMax=new int[arr.length];    // this array stores the max value from 0 to ith index at ith index\n        leftMax[0]=arr[0];                     \n        int[] rightMin=new int[arr.length];   // this array stores the min value from i to arr.length-1 at ith index\n        rightMin[arr.length-1]=arr[arr.length-1];\n        for(int i=1;i<arr.length;i++){\n            leftMax[i]=Math.max(leftMax[i-1],arr[i]);\n        }\n        for(int i=arr.length-2;i>=0;i--){\n            rightMin[i]=Math.min(rightMin[i+1],arr[i]);\n        }\n        \n        // now we traverse in leftMax array and rightMin array and compare the ith value of leftMax to (i+1)th value of rightMin array\n        // if we find leftMax[i] <= rightMin[i+1] , then it means all the elements from 0 to i is less then or equal to all the elelemts from i+1 to arr.length-1 , and it means if we sort the left and right part separatly then also we got a perfectly sorted array.\n       \n        int i=0;\n        int count=0;  // count of number of partitions\n        while(i<arr.length-1){\n            if(leftMax[i]<=rightMin[i+1]){\n                count++;\n            }\n            i++;\n        }\n        \n        return count+1;        // the number of chunks is one more than the number of partitions \n        \n    }\n}\n```
[]