C++ 4ms, FASTER THAN 96.95%
Suppose nums = {5,2,3,-1,2,1,3}, k=4\n\nNums in Descending Order = {5,3,3,2,2,1,-1} \nSo, our answer is 5,2,3,3\n1. Copied the original vector to nums1 \n2. Sor
Suppose nums = {5,2,3,-1,2,1,3}, k=4\n\nNums in Descending Order = {5,3,3,2,2,1,-1} \nSo, our answer is 5,2,3,3\n1. Copied the original vector to nums1 \n2. Sorted nums1 in Descending Order.\n3. Created a Unordered map and stored the first k elements in the map \n4. Now a for loop to traverse nums and check if k>0 and the current element exists in the map, if it does we decrement it\'s value by --large[nums[i]] and also --k.\n#### WHY WE ARE DOING --large[nums[i]]? \nAs we know our ans is 5,2,3,3 and nums = {5,2,3,-1,2,1,3}\n* 5 exist in map? YES\n* 2 exist in map? YES\n* 3 exist in map? YES\n* -1 exist in map? NO\n* 2 exist in map? YE-(IF WE DIDN\'T WRITE --large[nums[i]]) BUT WAIT\n### WE NEED 2 ONLY 1 TIME, THAT\'S WHY WE DID --large[nums[i]]\n#####     SO 2 CAN\'T BE TAKEN AS 2\'S COUNT IS 0\n* \t1 exist in map? NO\n* \t3 exist in map? YES\n\n```\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) \n    {\n        vector<int>nums1=nums;\n        sort(nums1.begin(),nums1.end(),greater<int>());\n        unordered_map<int,int>large;\n        for(int i=0; i<k; i++) ++large[nums1[i]];\n        vector<int>ans;\n        for(int i=0; i<nums.size(); i++)\n        {\n            if(k>0 && large[nums[i]])\n            {\n                ans.push_back(nums[i]);\n                --large[nums[i]];\n                --k;\n            }\n            else if(k<0)\n                break;\n        }\n        return ans;\n    }\n};
[]