2 C++ Solution - Priority Queue and summation
Priority Queue - O(n) space\n\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        \n        vector<int> v=arr;\n        sort(v.be
# Priority Queue - O(n) space\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        \n        vector<int> v=arr;\n        sort(v.begin(),v.end());\n        int i=0,j=0,ans=0;\n        priority_queue<int,vector<int>,greater<int>>pq;\n        while(i<v.size())\n        {\n            pq.push(arr[i++]);\n            while(!pq.empty() && pq.top()==v[j])\n            {\n                pq.pop();\n                j++;\n            }\n            if(pq.size()==0)ans++;\n        }\n        return ans;\n    }\n};\n```\n\n\n# Using sum - O(1) space\n\n```\nint maxChunksToSorted(vector<int>& arr) {\n        int sum1 = 0, sum2 = 0, ans = 0;\n        vector<int> t = arr;\n        sort(t.begin(), t.end());\n        for(int i = 0; i < arr.size(); i++) {\n            sum1 += t[i];\n            sum2 += arr[i];\n            if(sum1 == sum2) ans++;\n        }\n\treturn ans;\n}\n```
['C++']