Easy Solution || Greedy Approach || LeftMax And RightMin  ||O(N)
Intuition\nWe Cannot Make Chunk Untill Current Largest Element Doesn\'t Have Any element which are smaller than it on right hand side\n# Approach\nConsider the 
# Intuition\nWe Cannot Make Chunk Untill Current Largest Element Doesn\'t Have Any element which are smaller than it on right hand side\n# Approach\nConsider the arr=[3,2,1,5,4]\n**THOUGHT PROCESS**\nat i= 0 can we make a chunk here ?\nNo because there are smaller elements than 3 on its rhs\nat i= 1 can we make a chunk here ?\nNo because there are smaller elements than 2 on its rhs\nat i= 2 can we make a chunk here ?\nYes because there are no smaller elements than 1 on its rhs\nSo Number Of chunks=1;\nat i= 3 can we make a chunk here ?\nNo because there are smaller elements than 5 on its rhs\nat i= 4 can we make a chunk here ?\nYes because there are no smaller elements than 4 on its rhs\nSo Number Of chunks is equal to 2.\n**BUT** \nBut after thinking about more test cases i found that it will not work every testcase \nconsider array=[3,1,2,5,4]\nat i= 0 can we make a chunk here ?\nNo because there are smaller elements than 3 on its rhs\nat i= 1 can we make a chunk here ?\nYes because there are no smaller elements than 1 on its rhs\nBut it was Wrong , Because we have a 2 on the right of 1,\nSo if we break chunk as [3,1] and sorting it will doesn\'t ,make array as sorted.\n**So what should we track ?**\nThe Same Approach with Slight change :\nInstead Checking For every element ,we should track the larger elements from i=0 in the array.\n**How did it strike to me ?**\nconsider the same example where my first approach is failed\narr= [3,1,2,5,4]\nhere at i=1 and arr[i]=1 there no elements which are smaller than 1 on rhs.\nbut **we have a 3 on left of 1 and 2 on right of 1 where 3>2 which means even though we doesn\'t have any elements smaller than current element , we have elements which are smaller than its previous elements .\nso if we can track the maximum elements from the left and applying same logic will work here**\narr=[3,1,2,5,4]\nat i=0 currentmax=3 there are smaller elements than 3 on its rhs.\nat i=1 currentmax=3 there are smaller elements than 3 on its rhs.\nat i=2 currentmax=3 there are no smaller elements than 3 on its rhs\nhence we can make a chunk here.\nat i=3 currentmax=5 there are smaller elements than 5 on its rhs.\nat i=4 currentmax=5 there are no smaller elements than 5 on its rhs\nhence we can make a chunk here.\nso total number of chunks =2\nHope You understand the Solution\n**Please upvote if you understand the solution**\n\n\n\n\n\n\n# Complexity\n- Time complexity:\nO(N)\n- Space complexity:\'\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int n=arr.size();\n             vector<int>rightmin(n);\n             vector<int>leftmax(n);\n             // calculate maximum elements from left side\n             leftmax[0]=arr[0];\n             for(int i=1;i<n;i++)\n             {\n                leftmax[i]=max(leftmax[i-1],arr[i]);\n             }\n            // calculate minimum elements from right side\n          rightmin[n-1]=arr[n-1];\n          for(int i=n-2;i>=0;i--)\n          {\n              rightmin[i]=min(arr[i],rightmin[i+1]);\n          }\n         /*atleast there will be one chunk \n          the total array can be considered as a chunk */\n          int chunks=1;\n          for(int i=0;i<n-1;i++)\n          {\n                 if(leftmax[i]<=rightmin[i+1]) chunks++;\n          }\n          return chunks;\n\n    }\n};\n```
['Dynamic Programming', 'Greedy', 'Suffix Array', 'C++']