C++ O(N) solution with explanation
If the range [L, R) is one of the chunks, than the values in range [L,R) should be the same after sorting. \nWe can extend this to say that the values in range 
If the range [L, R) is one of the chunks, than the values in range [L,R) should be the same after sorting. \nWe can extend this to say that the values in range [0, R) should be the same after sorting(every chunk before [L, R) has the same property).\n\nTo check whether values in range [0, R) is the same after sorting, we only need to check \nif max of values in range [0,R) is smaller than or equal to the min of values in range [R, N). \nEach chunk is counted only once at its right boundary.\n```\nclass Solution {\npublic:\n    int maxChunksToSorted(vector<int>& arr) {\n        int N = arr.size();\n        // Max[i]:Max value in range [0, i)\n        vector<int> Max(N+1, INT_MIN);\n        for(int i = 1 ; i <= N ; ++i)\n            Max[i] = max(Max[i-1], arr[i-1]);\n        \n        // Min[i]:Min value in range [i,N)\n        vector<int> Min(N+1, INT_MAX);\n        for(int i = N - 1 ; i >= 0 ; --i)\n            Min[i] = min(Min[i+1], arr[i]);\n        \n        // Calculate Chunks\n        int nChunks = 0;\n        for(int i = 1 ; i <= N ; ++i){\n            // if max of range[0, i) <= min of range[i, N)\n            // add 1 to number of chunks.\n            nChunks += Max[i] <= Min[i];\n        }\n        return nChunks;\n    }\n};\n```
[]