[Java/Python] Easy and Straight Froward
Soluton 1\nCount numbers.\nO(nlogn) for sorting\nO(n^2) for check\nPython\npy\n    def maxChunksToSorted(self, arr):\n        res, c1, c2 = 0, collections.Count
# Soluton 1\nCount numbers.\nO(nlogn) for sorting\nO(n^2) for check\n**Python**\n```py\n    def maxChunksToSorted(self, arr):\n        res, c1, c2 = 0, collections.Counter(), collections.Counter()\n        for a, b in zip(arr, sorted(arr)):\n            c1[a] += 1\n            c2[b] += 1\n            res += c1 == c2\n        return res\n```\n<br>\n\n# Soluton 2\nCount prefix sum.\nO(nlogn) for sorting\nO(n) for check\n\n**Java**\nby @Chengyou0421\n```java\n    public int maxChunksToSorted(int[] arr) {\n        int[] sorted = arr.clone();\n        Arrays.sort(sorted);\n        int res = 0, sum1 = 0, sum2 = 0;\n        for (int i = 0; i < arr.length; i++) {\n            sum1 += arr[i];\n            sum2 += sorted[i];\n            if (sum1 == sum2) res += 1;\n        }\n        return res;\n    }\n```\n**Python**\nSuggested by @here0007\n```py\n    def maxChunksToSorted(self, A):\n        res, s1, s2 = 0, 0, 0\n        for a, b in zip(A, sorted(A)):\n            s1 += a\n            s2 += b\n            res += s1 == s2\n        return res\n```\n<br>
[]