Simple 9 Lines C++, O(n) time, O(n) space using stack.
Approach\nKeep track of maximum element found, pop from stack till current element is less than top of stack. Finally push the current max onto the stack.\n\n# 
# Approach\nKeep track of maximum element found, pop from stack till current element is less than top of stack. Finally push the current max onto the stack.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        stack<int> st;\n        int n = arr.size();\n        int curmax = -1;\n        for(int i = 0;i<n;i++){\n            curmax = max(curmax,arr[i]);\n            while(st.size() && st.top()>arr[i]){\n                st.pop();\n            }\n            st.push(curmax);\n        }\n\n        return st.size();\n\n\n    }\n};\n```
['C++']