C++ , with explanation and thought process
\n    lets say we have something like this\n    (a1----a2) | (a3-------a4) | (a5--------a6)\n       part1        part2          part3\n    these are the chunks 
\n    lets say we have something like this\n    (a1----a2) | (a3-------a4) | (a5--------a6)\n       part1        part2          part3\n    these are the chunks (sorting them individually sorts the entire array)\n    lets say after sorting our new array becomes the following \n    (b1----b2) | (b3-------b4) | (b5--------b6)\n        part1       part2           part3\n    so as the array is sorted , these properties should hold\n    b1 <= b2\n    b2 <= b3\n    b3 <= b4\n    b4 <= b5\n    b5 <= b6\n\n    so lets see what actually b1,b2,b3,b4,b5,b6 are\n    \n    b1 is the minimum element of the part1\n    b2 is the maximum element of part1\n\n    b3 is minimum element of part2\n    b4 is maximum element of part2\n\n    see these conditions b2 <= b3 and  b4 <= b5\n    these conditions tell us that whenever it is possible to create a partition here, the maximum of the current part should be less than \n    or equal to the minimum of the next part\n\n    so all we do is maintain leftMax and rightMin array and apply these checks\n\n    \n\n\n```\nclass Solution {\npublic:\n    \n    \n    int maxChunksToSorted(vector<int>& arr) {\n        if(arr.size() == 1) return 1;\n        if(arr.size() == 0) return 0;\n        \n        int n = arr.size();\n        vector<int> leftMax(n+1);\n        vector<int> rightMin(n+1);\n\n        int maxTillHere  = INT_MIN; \n        for(int i=0; i<n; i++)  {\n            maxTillHere = max(maxTillHere , arr[i]);\n            leftMax[i] = maxTillHere;\n        }\n            \n        leftMax[n] = leftMax[n-1];\n        \n        int minTillHere = INT_MAX;\n        for(int j=n-1; j>=0; j--) {\n            minTillHere = min(minTillHere , arr[j]);\n            rightMin[j] = minTillHere;\n        }\n        rightMin[n] = INT_MAX;\n\n        int cnt = 0;\n        for(int i=0; i<n; i++) \n        {\n            if(leftMax[i] <= rightMin[i+1]) cnt++;\n        }\n        return cnt;\n        \n    }\n};\n\n\n```
[]