C++ Simple and with algorithm Solution O(n) time and space both.
\nlet\'s take an example: \n                                                  ||          ||                   ||\narr[]           =         30       10       2
```\nlet\'s take an example: \n                                                  ||          ||                   ||\narr[]           =         30       10       20    ||    40    ||    60       50    ||    75       70\nleft_max        =         30       30       30    ||    40    ||    60       60    ||    75       75\nright _min      =         10       10       20    ||    40    ||    50       50    ||    70       70\n                                                  ||          ||                   ||\nhere we need a variable that will count the number of chunks.\nso take int count = 0;\n\nwhen we encounter (left_max[i] <= right_min) update count = count + 1.\nbut in the actual code i\'m taking only right_min vector not left_max,\nsince we can generate left_min value simultaneously within the loop.\n\nso that\'s it\n\n```\n**PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask.**\n```\nint maxChunksToSorted(vector<int>& arr) {\n       \n        int n = arr.size();\n        vector<int> rightmin(n+1,INT_MAX);\n        for(int i=n-1;i>=0;i--)\n        {\n            rightmin[i] = min(arr[i],rightmin[i+1]);\n        }\n        int count = 0;\n        int leftmax = INT_MIN;\n        for(int i=0;i<n;i++)\n        {\n            leftmax = max(leftmax,arr[i]);\n            if(leftmax <= rightmin[i+1])\n            {\n                count++;\n            }\n        }\n        return count++;\n        \n    }\n```\n**PLEASE UPVOTE if you like \uD83D\uDE01 If you have any question, feel free to ask.**\n
['C', 'C++']