768. Max Chunks To Make Sorted II You are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return the largest number of chunks we can make to sort the array. 123456789101112131415161718192021class Solution {public: int maxChunksToSorted(vector<int>& arr) { unordered_map<int, int> counter; vector<int> sorted = arr; sort(sorted.begin(), sorted.end()); int res = 0, n = arr.size(); for(int i = 0; i < n; i++) { if(++counter[arr[i]] == 0) counter.erase(arr[i]); if(--counter[sorted[i]] == 0) counter.erase(sorted[i]); if(counter.empty()) res++; } return res; }};