C++ 3 approaches (each commented with intuition)
\n//Approach-1 : Time - O(n), Space - O(n)\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size();\n        \n   
```\n//Approach-1 : Time - O(n), Space - O(n)\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size();\n        \n        vector<int> rightMin(n);\n        rightMin[n-1] = arr[n-1];\n        \n        for(int i = n-2; i>=0; i--)\n            rightMin[i] = min(rightMin[i+1], arr[i]);\n        \n        int leftMax = arr[0];\n        \n        int count = 0;\n        \n        /*\n            If current leftMax is less than or equal to\n            minimum of all elements to its right,\n            it means it can\'t have an impact further.\n            It belongs to a chunk till this point only.\n            And then, we move ahead.\n        */\n        \n        for(int i = 0; i<n-1; i++) {\n            leftMax = max(leftMax, arr[i]);\n            if(leftMax <= rightMin[i+1])\n                count++;\n        }\n        \n        return count+1;\n    }\n};\n```\n\n```\n//Approach-2 (Using similar concept of "Max Chunks To Make Sorted I"\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size();\n        vector<int> sorted(arr);\n        sort(begin(sorted), end(sorted));\n        \n        vector<int> MAX(n);\n        MAX[0] = arr[0];\n        for(int i = 1; i<n; i++)\n            MAX[i] = max(MAX[i-1], arr[i]);\n        \n        int rightMax = MAX[n-1];\n        int count    = 0;\n        for(int  i = n-1; i>=0; i--) {\n            if(sorted[i] == MAX[i]) {\n                if(sorted[i] > rightMax)\n                    continue; //because we need to include this as well for being sorted correctly\n                \n                rightMax = arr[i];\n                count++;\n            }\n        }\n        \n        return count;\n    }\n};\n```\n\n```\n//Approach-3 (O(nlogn)) But smartest approach\n/*\n    Why does this work ?\n    Intuition -\n    Let "sorted" be the input "arr" array after being sorted.\n    A "chunk" is an interval [i, j] such that arr[i], ..., arr[j]\n    is just a permutation of sorted[i], ..., sorted[j].\n    \n    Since each chunk is just a permutation, the sums of these\n    two lists of numbers will be equal.\n    And the point where cumulative sum gets equal, that\'s the\n    point of partition of chunk.\n*/\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n = arr.size();\n        vector<int> sorted(arr);\n        sort(begin(sorted), end(sorted));\n        \n        long long sum1 = 0, sum2 = 0;\n        int count = 0;\n        for(int i = 0; i<n; i++) {\n            sum1 += arr[i];\n            sum2 += sorted[i];\n            \n            if(sum1 == sum2)\n                count++;\n        }\n        \n        return count;\n    }\n};\n```
[]