C++ || DP || TLE (128 Passed out of 136) || O(n^2) || Partition based
\n bool check(vector<int> &nums , int l , int r , vector<int> &sorted_arr)\n    {\n        unordered_map< int , int > mp;\n        \n        for(int i=l;i<=r;i+
```\n bool check(vector<int> &nums , int l , int r , vector<int> &sorted_arr)\n    {\n        unordered_map< int , int > mp;\n        \n        for(int i=l;i<=r;i++)\n        {\n            mp[sorted_arr[i]]++;\n        }\n        \n        for(int i=l;i<=r;i++)\n        {\n            if(mp.find(nums[i])==mp.end())\n            {\n                return false;\n            }\n            else\n            {\n                mp[nums[i]]--;\n                \n                if(mp[nums[i]]==0)\n                {\n                    mp.erase(nums[i]);\n                }\n            }\n        }\n        \n        return true;\n    }\n    \n    int dp[2005];\n    \n    int func(vector<int> &nums , int l , int r ,  vector<int> &sorted_arr)\n    {\n        if(l>r)\n        {\n            return 0 ;\n        }\n        \n        if(dp[l]!=-1)\n        {\n            return dp[l];\n        }\n        \n        int ans=0;\n        \n        int val=0;\n        \n        for(int k=l;k<=r;k++)\n        {\n            // partition \n            \n            if(check(nums , l , k , sorted_arr))\n            {\n                val = 1 + func(nums , k+1 , r , sorted_arr);\n                ans=max(ans , val);\n            }\n            \n            \n        }\n        \n        return dp[l]=ans;\n    }\n    \n    int maxChunksToSorted(vector<int>& nums) {\n        \n        vector<int> arr=nums;\n        \n        sort(arr.begin() , arr.end());\n        \n        memset(dp , -1 , sizeof(dp));\n        \n        \n        return func(nums , 0 , nums.size()-1 , arr);\n        \n        \n        \n    }\n```
['Array', 'Dynamic Programming', 'C', 'C++']