why your code is so simple
Guys... I spent like two hours for this :( which is sad. I use RMQ to solve this prob.....\nAny idea to improve my code? I think I might doing it overkill with 
Guys... I spent like two hours for this :( which is sad. I use RMQ to solve this prob.....\nAny idea to improve my code? I think I might doing it overkill with less efective\n\n\'\'\'\n\n\t#include <bits/stdc++.h>\n\tusing namespace std;\n\t\n\tclass Solution {\n\tpublic:\n    void generateTable (vector<vector<int>>& table) {\n        int n = table[0].size();\n        int p = 0;\n        while (n - (1 << p) > 0) {\n            vector<int> temp;\n            int add = 1 << p;\n            n -= add;\n            for (int i = 0; i < n; i++) {\n                temp.push_back(min(table[p][i], table[p][i + add]));\n            } p++;\n            table.push_back(temp);\n        }\n    }\n    int getRMQ (int l, int r, vector<vector<int>>& table) {\n        int n = r - l + 1;\n        int p = log2(n);\n        int k = 1 << p;\n        return min(table[p][l], table[p][r - k + 1]);\n    }\n    \n    int maxChunksToSorted(vector<int>& arr) {\n        vector<vector<int>> table{arr};\n        vector<int> arr2 = arr;\n        sort(arr2.begin(), arr2.end());\n        \n        generateTable(table);\n        \n        int n = arr.size();\n        int ans = 0, last = n;\n        for (int i = n - 1; i >= 0; i--) for (int j = 0; j < last; j++) {\n            if (arr[j] == arr2[i]) {\n                int add = 0, red = 0;\n                for (int k = last - 1; k > j; k--) {\n                    bool con1 = arr[k] == arr[j];\n                    bool con2 = arr[k] <= getRMQ(k, last - 1, table);\n                    if (con1) red++;\n                    if (con1 && con2)\n                        ++add;\n                    else\n                        break;\n                }\n\t\t\t\tif ((last == n) || (arr[j] <= getRMQ(min(last, n - 1), n - 1, table))) ans += add + 1;\n\t\t\t\t\ti -= red;\n\t\t\t\t\tlast = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n        return ans;\n\t\t}\n\t};\n\'\'\'
['Two Pointers']