C++ | Time Complexity 100 % | O(n)
Approach : A chunk can only be created when the maximum element in the left of the subarray is less  than or equal to the smallest element in the right of the s
Approach : A chunk can only be created when the maximum element in the left of the subarray is less  than or equal to the smallest element in the right of the sub array .\n\nEg :  let nums = {  14 , 16 , 12 , 20 , 18 , 22 , 28 , 26 , 24 } ;\n\nhere we will compute max element so far from left to right as we have to check the maximum in the left subarray and compute min element so far from right to left as we have to check the min in the right subarray . \n\nmaxArr = { 14 , 16 , 16 , 20 , 20 , 22 , 28 , 28 , 28 }\nminArr = { 12 , 12 , 12 , 18 , 18 , 22 , 24 , 24 , 24 }\n\nhere we can see the at the 2nd idx the max element on the left is less than the min element on the right so , we have a chunk here \n\nhere n+1 length of vector and INT_MAX is used to handle the last chunk. \n\n\t\n\tint maxChunksToSorted(vector<int>& nums) {\n\t\t\tint n = nums.size() ;\n\t\t\tvector<int> minArr(n+1,INT_MAX) ; \n\t\t\tvector<int> maxArr(n+1,INT_MAX) ; \n\t\t\tint chunks = 0 ;\n\t\t\tmaxArr[0] = nums[0] ; \n\t\t\tminArr[n-1] = nums[n-1] ;\n\t\t\t// APPENDING MAX ELEMENTS \n\t\t\tfor(int i = 1 ; i < n ; i++){\n\t\t\t\tmaxArr[i] = max(maxArr[i-1] , nums[i]) ; \n\t\t\t}\n\t\t\t// APPENDING MIN ELEMENTS \n\t\t\tfor(int i = n-2 ; i >=0 ; i--){\n\t\t\t\tminArr[i] = min(minArr[i+1] , nums[i]) ; \n\t\t\t}\n\t\t\t// MAKING CHUNKS\n\t\t\tfor(int i = 0 ; i < n ; i++){\n\t\t\t\tif(maxArr[i] <= minArr[i+1]){ \n\t\t\t\t\tchunks++ ; \n\t\t\t\t}\n\t\t\t} \n\t\t\treturn chunks ; \n\t\t}
[]