Solution by using two pointers approach
Intuition\n Describe your first thoughts on how to solve this problem. \nTwo pointers\n\n# Approach\nTwo Pointers Approach\n\n# Complexity\n- Time complexity:\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo pointers\n\n# Approach\nTwo Pointers Approach\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n=arr.size();\n        vector<int> v=arr;\n        sort(v.begin(),v.end());\n        map<int,set<int>> m;\n        for(int i=0;i<n;i++)\n        {\n            m[v[i]].insert(i);\n        }\n        for(int i=0;i<n;i++)\n        {   auto it=m[arr[i]].begin();\n        int k=(*it);\n            m[arr[i]].erase(it);\n            arr[i]=k;\n            \n        }\n        int curr=0,maxi=-1;\n        int ans=0;\n        while(maxi<n-1&&curr<n)\n        {\n            maxi=max(maxi,arr[curr]);\n            if(maxi==n-1){ans++; break;}\n            if(arr[curr]<=curr&&maxi==curr){ans++;}\n            curr++;\n            \n        }\n        return ans;\n    }\n};\n```
['C++']