Solution
C++ []\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n=arr.size();\n        vector<int> rightMin(n+1,0);\n        right
```C++ []\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n=arr.size();\n        vector<int> rightMin(n+1,0);\n        rightMin[n]=INT_MAX;\n        for(int i=n-1;i>=0;i--){\n            rightMin[i]=min(arr[i],rightMin[i+1]);\n        }\n        int leftMax=-1;\n        int chunks=0;\n        for(int i=0;i<n;i++){\n            leftMax=max(leftMax,arr[i]);\n            if(leftMax<=rightMin[i+1]){\n                chunks++;\n            }\n        }\n        return chunks;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def maxChunksToSorted(self, A: List[int]) -> int:\n        A_cp = A.copy()\n        A_cp.sort()\n        n = len(A)\n        res, sum, sum_cp = 0, 0, 0\n        for i in range(n):\n            sum += A[i]\n            sum_cp += A_cp[i]\n            if sum == sum_cp:\n                res += 1\n        return res        \n```\n\n```Java []\nclass Solution {\n   public int maxChunksToSorted(int[] arr) {\n        int n = arr.length;\n        int[] maxOfLeft = new int[n];\n        int[] minOfRight = new int[n];\n\n        maxOfLeft[0] = arr[0];\n        minOfRight[n-1]=arr[n-1];\n        for (int i=1;i<n;i++)\n        {\n            maxOfLeft[i]=Math.max(maxOfLeft[i-1],arr[i]);\n        }\n        for (int i=n-2;i>=0;i--)\n        {\n            minOfRight[i]=Math.min(minOfRight[i+1],arr[i]);\n        }\n        int res=0;\n        for (int i=0;i<n-1;i++)\n        {\n            if (maxOfLeft[i]<=minOfRight[i+1]) res++;\n        }\n        return res + 1;\n    }\n}\n```\n
['C++', 'Java', 'Python3']