C++ solution O(N) Time complexity| With proper explaination
Steps to follow:\n1) make a vector right of size arr.size() +1 which will having minimum from i th index to arr.size() -1;\n2) make a variable left_max and coun
**Steps to follow:**\n1) make a vector right of size arr.size() +1 which will having minimum from i th index to arr.size() -1;\n2) make a variable left_max and count_chunks to calculate the maximum of chunks required to make the given array sorted.\n3) iterate from 0th index to arr.size()\n4) keep updating left_ max that is max of left_max and arr[i]\n5) if the left-max is smaller or equal to(why equal to also, because we want to have maximum chunks) right[i+1] than increment count_chunks\n6) count_chunks will return the maxium chunks required to make an array sorted\n\nThis solution has **O(N) time complexity**\n\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        vector<int>right(arr.size()+1);\n        right[arr.size()] = INT_MAX;\n        \n        for(int i =arr.size()-1 ; i>= 0; i--){\n           right[i] = min(right[i+1], arr[i]);\n        }\n        int left_max = INT_MIN;\n        int count_chunks =0;\n        for(int i =0; i<arr.size(); i++){\n            left_max = max(left_max, arr[i]);\n            if(left_max <= right[i+1]) count_chunks++;  \n        }\n        return count_chunks;\n    }\n};\n```\n**Please upvote if you like the solution and comment if have doubts**
['C', 'C++']