✅✅Faster || Easy To Understand || C++ Code
Using Two Extra Arrays\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n 
* ***Using Two Extra Arrays***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        \n        int n = arr.size();\n        \n        // left_max[i] will store the maximum till ith from left side\n        \n        vector<int> left_max(n, 0);\n        \n        // fill left_max\n        \n        left_max[0] = arr[0];\n        \n        for(int i = 1; i < n; i++)\n        {\n            left_max[i] = max(left_max[i - 1], arr[i]);\n        }\n        \n        // right_min[i] will store the minimum till ith from right side\n        \n        vector<int> right_min(n, 0);\n        \n        // fill right_min array\n        \n        right_min[n - 1] = arr[n - 1];\n        \n        for(int i = n - 2; i >= 0; i--)\n        {\n            right_min[i] = min(right_min[i + 1], arr[i]);\n        }\n        \n        // if at any index i we are having maximum till ith from left side is smaller than minimum till (i + 1)th from right side, then we found chunk\n        \n        int count = 0;\n        \n        for(int i = 0; i < n - 1; i++)\n        {\n            if(left_max[i] <= right_min[i + 1])\n            {\n                count++;\n            }\n        }\n        \n        // there will be always a partition at (n - 1)th index\n        \n        count++;\n        \n        return count;\n    }\n};\n```
['Array', 'Greedy', 'C', 'C++']