[C++] Simple NlogN Sorting + HashMap based solution. Updated O(n) Stack solution
Time : O(nlogn) solution\n\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& A) {\n        unordered_map<int, int> mp;\n        vector<int> exp
Time : O(nlogn) solution\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& A) {\n        unordered_map<int, int> mp;\n        vector<int> expected(A); // this is the expected result after sorting\n        sort(expected.begin(), expected.end());\n        int n = A.size(), chunks = 0;\n        for(int i = n - 1; i >= 0; i--)\n        {\n            mp[expected[i]]++;\n            mp[A[i]]--;\n            if(mp[A[i]] == 0)\n                mp.erase(A[i]);\n            if(mp[expected[i]] == 0)\n                mp.erase(expected[i]);\n            if(mp.empty()) // both the arrays have seen same elements in sorted as well as normal order, i.e. a chunk can be cut.\n                chunks++;\n        }\n        return chunks;\n    }\n};\n```\nUpdate : \nTime : O(n) solution\nThe stack stores the ranges of elements, when an overlap of range occurs, pop the previous range from stack and add the new range\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& A) {\n        stack<int> s;\n        int curMax = 0;\n        for(int i = 0; i < A.size(); i++)\n        {\n            curMax = (s.empty() ? A[i] : max(s.top(), A[i])); // evaluate the current-Max element till now\n            while(!s.empty() && s.top() > A[i]) // if the current element is smaller than previous max, \n            // then it\'s a part of the previous chunk. Hence pop from stack and push later the updated range.\n                s.pop();\n            s.push(curMax);\n        }\n        return s.size();\n    }\n};\n```
['C', 'Sorting']