C++ Solution | Explanation | Hashing
Algorithm:\nAcc to the constraints you cannot do it using recursion it gives TLE.\n\nThink to optimise it.\nYou need the k largest values of the array to make t
Algorithm:\nAcc to the constraints you cannot do it using recursion it gives TLE.\n\nThink to optimise it.\nYou need the k largest values of the array to make the maximum sum. So that can be got by the last ```K``` values of a sorted array.\nSo we think to sort the array.\nNow extract the last k values which gives the maximum sum. [ kept it in temp]\n\nNow we need to think how to return these values in their original order.\nWhat if you have the elements in some DS and you traverse the original array. As soon as you see that the presently traversed element is in the DS [will think of this in the next step] you push to the ```answer``` array.\n\ncool. soo now what DS to store the values. \n a. if we consider a set then the duplicates values will be lost and original ordering will mess up.\n b. can use a map. since the value and its frequency can be mantained you can put the values the exact number of times in the output array as in the input array .\n \n Now just traverse the original array. check if the map has the freq greater than 0. if yes push to output array and decrement the frequency ( mark it as seen ) \n \n \n Here you goo.. \n```\nvector<int> maxSubsequence(vector<int>& nums, int k) {\n        vector<int> original = nums;\n        sort(nums.begin(), nums.end());\n        vector<int> temp(nums.end()-k, nums.end());\n\n        unordered_map<int,int>mp;\n        for(int x: temp){\n            mp[x]+=1;\n        }\n        vector<int>ans;\n        for(int x : original){\n            \n                if(mp[x]-- >0){\n                    ans.push_back(x);\n                }\n        }\n        return ans;\n    }\n```
['C', 'Sorting']