C++ | O( N log(N) + N )  | With Picture explanation and Comments
Credits to :  https://leetcode.com/votrubac for the approach\nI will give my explanation to this approach .\nUPVOTE would be really appreciated !\n(Note : Steps
Credits to :  [https://leetcode.com/votrubac](http://) for the approach\nI will give my explanation to this approach .\nUPVOTE would be really appreciated !\n(Note : Steps will become clear by example )\n* Step 1 : Here we will make an array of indices and we will sort it (using a stable sort ) according to the values given in the input array.\n* Step 2: Traverse in the index array and increment count when the max-index-till-now reaches its index.\n\n EXAMPLE :\n\n![image](https://assets.leetcode.com/users/anime_guy2506/image_1587759073.png)\n\nNow when we traverse in the sorted index array , when then max index till now is equal to the current index we have reached end of a partition and we increment count.\nAt last return count !\n\nAlso,Lambda function is used in sorting beacuse we need access to the input vector while sorting.\n\n```\n\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size();\n        \n//         This will store indices from 0 to n-1\n        vector<int> index_vector(n);\n        for(int i=0;i<n;i++){\n            index_vector[i] = i;\n        }\n        \n//         place the indices as if they were the values themselves\n        sort(index_vector.begin(),index_vector.end(),[&arr](int &a,int &b){\n            if(arr[a]==arr[b])\n                return a<b;\n            return arr[a]<arr[b];\n        });\n        \n//         When the max till now reaches to its position increment count\n        int count = 0,max_index = 0;\n        for(int i=0;i<n;i++){\n            max_index = max(max_index,index_vector[i]);\n            if(max_index == i)\n                count++;\n        }\n        return count;\n    }\n};\n```
[]