C++ | Using hashing | re-arranging answer after sorting
\n\t\tvector<int> temp = nums, ans;\n        unordered_map<int, int> mp;\n        sort(temp.begin(), temp.end());\n        int i = nums.size() - 1;\n        int
```\n\t\tvector<int> temp = nums, ans;\n        unordered_map<int, int> mp;\n        sort(temp.begin(), temp.end());\n        int i = nums.size() - 1;\n        int ptr = 0;\n        while(ptr++ < k) ans.push_back(temp[i--]);\n        for(auto it : ans) mp[it]++;\n        ans.clear();\n        for(int i = 0; i < nums.size(); i++) {\n            if(mp[nums[i]]-- > 0 ) {\n                ans.push_back(nums[i]);\n                ptr++;\n            }\n        }\n        return ans;\n```
[]