768. Max Chunks To Make Sorted II
class Solution {\npublic:    \n    int maxChunksToSorted(vector& arr) {\n        int n = arr.size(), i, j;\n        vectormin_num(n, 0);\n        min_num[n-1] =
class Solution {\npublic:    \n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size(), i, j;\n        vector<int>min_num(n, 0);\n        min_num[n-1] = arr[n-1];\n        for (i = n-2; i >= 0; --i) min_num[i] = (arr[i] < min_num[i+1])? arr[i] : min_num[i+1];\n        int maxv = 0, ans = 0;\n        for(i = 0; i < n; ++i) {\n            maxv = arr[i];            \n            for (j = i+1; j < n; ++j) {\n                if(maxv <= min_num[j]) break;\n                if(maxv < arr[j]) maxv = arr[j];\n            }\n            ++ans;\n            i = j - 1;\n        }\n        return ans;\n    }\n};
['C', 'C++']