Simple Stack O(n) Solution
\n    int maxChunksToSorted(vector& arr) {\n        \n        if(arr.size()==0)\n            return 0;\n        \n        stack st;\n        st.push(arr[0]);\n 
\n    int maxChunksToSorted(vector<int>& arr) {\n        \n        if(arr.size()==0)\n            return 0;\n        \n        stack<int> st;\n        st.push(arr[0]);\n        for(int i=1;i<arr.size();i++){\n            \n            if(arr[i]>=st.top()){\n                st.push(arr[i]);\n                continue;\n            }\n            int temp = st.top();\n            while(!st.empty() && arr[i] < st.top())\n                st.pop();\n            \n            st.push(temp); \n        }\n        return st.size();\n    }
[]