Best Solution Using Heap
We can use a heap to store the greatest k elements from the list along with their indices. \nOnce we have that we can use a set to store those indices and use t
We can use a heap to store the greatest k elements from the list along with their indices. \nOnce we have that we can use a set to store those indices and use that list to add the values to the answer. \n\n```\nclass Solution:\n    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:\n        newNums = [[nums[i], i] for i in range(len(nums))]\n        heap = []\n        \n        for i in range(len(nums)):\n            heappush(heap, newNums[i])\n            if len(heap) > k:\n                heappop(heap)\n        \n        setOfIndex = set()\n        for i in range(len(heap)):\n            setOfIndex.add(heap[i][1])\n\n        maxSeq = []\n        for i in range(len(nums)):\n            if i in setOfIndex:\n                maxSeq.append(nums[i])\n            \n        return maxSeq\n\t\n```\n            \n        \n                    \n        \n
['Python']