Python Simple Solution | 100% Time
Code:\n\nclass Solution:\n    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:\n        tuple_heap = [] # Stores (value, index) as min heap\n    
## Code:\n```\nclass Solution:\n    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:\n        tuple_heap = [] # Stores (value, index) as min heap\n        for i, val in enumerate(nums):\n            if len(tuple_heap) == k:\n                heappushpop(tuple_heap, (val, i)) # To prevent size of heap growing larger than k\n            else:\n                heappush(tuple_heap, (val, i))\n\t\t# heap now contains only the k largest elements with their indices as well.\n        tuple_heap.sort(key=lambda x: x[1]) # To get the original order of values. That is why we sort it by index(x[1]) & not value(x[0])\n        ans = []\n        for i in tuple_heap:\n            ans.append(i[0])\n        return ans\n```\nGive an \u2B06\uFE0Fupvote if you found this article helpful.
['Heap (Priority Queue)', 'Python', 'Python3']