Python || Sorting+Hashmap || O(n logn)
We have 2 arrays. One sorted and one unsorted.Now traverse over both.For one array increment by one for every value and for other decrement.We delete an element
We have 2 arrays. One sorted and one unsorted.Now traverse over both.For one array increment by one for every value and for other decrement.We delete an element from map when its count is reached 0, it means when one element who was in excess in one array has been compensated by the same value in other array.(basically its +1-1=0 or +2-2=0 .....)Finally we will have a chunk when we have common elements in both subarrays i.e. when length of map will be 0.\n```\nclass Solution:\n    def maxChunksToSorted(self, arr: List[int]) -> int:\n        arr2=sorted(arr)\n        n=len(arr)\n        cnt={}\n        ans=0\n        for i in range(n):\n            if arr[i] not in cnt:\n                cnt[arr[i]]=1\n            else:\n                cnt[arr[i]]+=1\n            if cnt[arr[i]]==0:\n                del cnt[arr[i]]\n            if arr2[i] not in cnt:\n                cnt[arr2[i]]=-1\n            else:\n                cnt[arr2[i]]-=1\n            if cnt[arr2[i]]==0:\n                del cnt[arr2[i]]\n            ans+=(1 if len(cnt)==0 else 0)\n        return ans\n            \n```
['Sorting', 'Python3']