Python solution
Given an array [a_1, a_2, ..., a_n], we can make a split at some index i, such that sorting [a_1, ..., a_i] and [a_(i+1), ..., a_n] sorts the whole array, if an
Given an array `[a_1, a_2, ..., a_n]`, we can make a split at some index `i`, such that sorting `[a_1, ..., a_i]` and `[a_(i+1), ..., a_n]` sorts the whole array, if and only if `max(a_1,...,a_i) < min(a_(i+1),...a_n)`. Hence a simple algorithm would be to initialize an array `max_left` of length `n`, and iterate over `arr` from the left, and populate `max_left[i]` with the maximum in `[a_1, ..., a_i]`. Similarly, we initialize an array `min_right` of length `n`, and iterate over `arr` from the right, and populate `min_right[i]` with the minimum in `[a_i, ..., a_n]`. Finally, we initialize a `counter = 1`, and iterate `i` over `range(n-1)`, and compare `max_left[i]` with `min_right[i+1]`, if `max_left[i] <= min_right[i+1]`, we increment the counter by `1`. Finally, we return `counter`.\n\nTime complexity: `O(n)`, space complexity: `O(n)`.\n\n```\nclass Solution(object):\n    def maxChunksToSorted(self, arr):\n        """\n        :type arr: List[int]\n        :rtype: int\n        """\n        n = len(arr)\n        min_right = [0]*n\n        max_left = [0]*n\n        \n        for i in range(n):\n            if i == 0:\n                max_left[i] = arr[i]\n            else:\n                max_left[i] = max(arr[i], max_left[i-1])\n        for i in range(n-1, -1, -1):\n            if i == n-1:\n                min_right[i] = arr[i]\n            else:\n                min_right[i] = min(arr[i], min_right[i+1])\n        \n        res = 1\n        for i in range(n-1):\n            if max_left[i] <= min_right[i+1]:\n                res += 1\n        return res\n```
[]