Find Subsequence of Length K With the Largest Sum
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an integer array nums and an integer k, choose k positions of nums so that the chosen values have the largest possible sum, and return those values **in their original order**.
When equal values make more than one choice of positions optimal, pick the positions greedily from the left: among elements with the same value, prefer the one with the smaller index. (Equivalently, return the optimal choice whose sorted index list is lexicographically smallest.)
Examples
Constraints
- 1 <= nums.length <= 1000
- -10^5 <= nums[i] <= 10^5
- 1 <= k <= nums.length
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.