Answer: LENDINGKART Hiring | On-Campus OA (2025) | Find Subsequence of Length K With the
Answer · Posted Jun 2026
Approach To maximize the subsequence sum: Store indices of all elements. Sort indices by their corresponding values in descending order. Select the top k indices. Sort these selected indices by original position. Build the subsequence using those indices. This guarantees: Maximum sum. Original relative order maintained. Strategy Create an array of indices. Sort by value descending. Take the first k indices. Sort chosen indices by original index. Construct result. Java Solution: import java.util.*; class Solution { public int[] maxSubsequence(int[] nums, ...
The full answer & interview discussion are available to premium members.
Log in Create a free account