Back to course home
0% completed
Solution: Find Subsequence of Length K With the Largest Sum
Problem Statement
Given an integer array nums
and a positive integer k
, return any subsequence
of nums
of length k
, which has the largest sum
.
A subsequence
maintains the original order
of array elements but may exclude some
, without reordering
the remaining ones.
Examples
-
Example 1:
- Input:
nums = [5, -2, 3, 8], k = 2
- Expected Output:
[5, 8]
- Justification: The subsequence
[5, 8]
gives the largest sum of13
, which is the maximum sum we can obtain from any subsequence of length2
.
- Input:
-
Example 2:
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!