2099. Find Subsequence of Length K With the Largest Sum

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2099

class Solution:
    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:
        idx = list(range(len(nums)))
        idx.sort(key=lambda i: nums[i])
        return [nums[i] for i in sorted(idx[-k:])]