A very good question on stack
\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        stack<int>st;\n        for(int i=0; i<arr.size(); i++){\n            int cur
```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        stack<int>st;\n        for(int i=0; i<arr.size(); i++){\n            int current_max;\n             if(st.size()==0){\n                 current_max=arr[i];\n             }\n            else{\n                current_max=max(arr[i],st.top());\n            }\n            while(st.size()>0&&arr[i]<st.top()){\n                st.pop();\n            }\n            st.push(current_max);\n        }\n        return st.size();\n    }\n};\n```
['Stack']