Simple solution using heap ✅✅👌| optimized Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve the problem of finding the subsequence of k largest elements while maintaining
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve the problem of finding the subsequence of `k` largest elements while maintaining their original order, we can leverage a min-heap (priority queue) to efficiently track the top k largest elements. This allows us to efficiently manage the `size` of the subsequence we need.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Using a Min-Heap:\n* Insert elements from the array into the min-heap.\n* If the size of the heap exceeds k, remove the smallest element. This ensures that the heap always contains the k largest elements seen so far.\n2. Frequency Map:\n* Use an unordered map to count the occurrences of the elements in the heap.\n* This helps to handle duplicates and ensure that we correctly pick elements from the original array.\n3. Constructing the Result:\n* Iterate through the original array and add elements to the result vector if they are present in the frequency map.\n* Decrement the count in the map for each element added to the result.\n# Complexity\n- Time complexity: O(nlogk)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n\n        priority_queue<int, vector<int>, greater<int>> pq;\n\n        for(auto i : nums)\n        {\n            pq.push(i);\n            if(pq.size() > k )\n            {\n                pq.pop();\n            }\n        }   \n\n        unordered_map<int, int> mp;\n\n        while( !pq.empty() )\n        {\n            mp[pq.top()]++;\n            pq.pop();\n        }\n\n        vector<int> v;\n\n        for(auto i : nums)\n        {\n            if( mp[i] > 0 )\n            {\n                v.push_back(i);\n                mp[i]--;\n            }\n        }\n\n        return v;\n    }\n};\n```
['Sorting', 'Heap (Priority Queue)', 'C++']