C++ easy solution (beats 100%), recording min-max info for each chunk
\nclass Solution {\npublic:\n    typedef pair<int,int> IntPair;\n    int maxChunksToSorted(vector<int>& arr) {\n        // we only need to maintain the {min, ma
```\nclass Solution {\npublic:\n    typedef pair<int,int> IntPair;\n    int maxChunksToSorted(vector<int>& arr) {\n        // we only need to maintain the {min, max} info for each chunk\n        vector<IntPair> minMax;\n        \n        // first, there\'s only one chunk: arr[0]\n        minMax.push_back({arr[0], arr[0]});\n        \n        // starting from arr[1], we have 3 situations:\n        for(int i=1;i<arr.size();i++){\n            int last=minMax.size()-1;\n            if(arr[i]>=minMax[last].second){\n                // 1) if (arr[i] >= last chunk\'s largest number), we create a new chunk\n                minMax.push_back({arr[i], arr[i]});\n            }else if(arr[i]<minMax[last].first){\n                // 2) if (arr[i] < last chunk\'s smallest number), we should look back\n                int newMin=arr[i];\n                int newMax=minMax[last].second;\n                // because we must make sure arr[i] will be in a particular chunk[j],\n                // so that chunk[j-1]\'s largest < arr[i] < chunk[j]\'s largest.               \n                minMax.pop_back();\n                for(int j=last-1; j>=0 && arr[i]<minMax[j].second; j--){\n                    newMin=min(newMin, minMax[j].first);\n                    newMax=max(newMax, minMax[j].second);\n                    minMax.pop_back();\n                }\n                // once we found the chunk[j], we can pop_back all chunks after [j],\n                // and push_back the new correct chunk we\'ve just found out.\n                minMax.push_back({newMin, newMax});\n            } // 3) otherwise, we do nothing\n        }\n        \n        return minMax.size();\n    }\n};\n```
[]