Skip to content

2099. Find Subsequence of Length K With the Largest Sum #1862

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find a subsequence of length k from the given array nums that has the largest possible sum. A subsequence is derived by deleting some elements without changing the order of the remaining elements. The solution involves selecting the k largest elements from the array and returning them in their original order.

Approach

  1. Problem Analysis: The goal is to maximize the sum of a subsequence of length k. The optimal approach involves selecting the k largest elements in the array. However, these elements must appear in the subsequence in the same order as they appear in the original array.
  2. Intuition: The largest sum is achieved by selecting the k largest elements. Since the order of el…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jun 28, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jun 28, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants