Simple C++ code | O(N) | Monotonic Stack solution | 
Approach -> Monotonic StackComplexity

Time complexity : O(N)


Space complexity : O(N)

Code
# Approach -> Monotonic Stack

# Complexity
- Time complexity : O(N)

- Space complexity : O(N)

# Code
```cpp []
class Solution {
public:
    int maxChunksToSorted(vector<int>& arr) {

        int n = arr.size();
        stack<int> st;

        for(int i=0; i<n; i++){
            int ele = arr[i];
            while(!st.empty() && arr[i] < st.top()){
                ele = max(st.top(), ele);
                st.pop();
            }
            st.push(ele);
        }
        
        return st.size();
    }
};
```
['Array', 'Stack', 'Monotonic Stack', 'C++']