2204. Find Subsequence of Length K With the Largest Sum
My accepted Python solution to LeetCode problem 2204, Find Subsequence of Length K With the Largest Sum, running in 4ms.
- Difficulty: Easy
- Python
- Runtime 4ms
- Memory 17.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4ms, memory 17.7MB, accepted 2025-12-31.
class Solution:
def maxSubsequence(self, nums: List[int], k: int) -> List[int]:
# Get indices of k largest elements
indexed = [(num, i) for i, num in enumerate(nums)]
indexed.sort(reverse=True)
indices = sorted([i for num, i in indexed[:k]])
return [nums[i] for i in indices]