Maximum Sum Increasing Subsequence of Length K Problem Statement
You are given an array NUMS
consisting of N integers and an integer K. Your task is to determine the maximum sum of an increasing subsequence of length K.
Input:
The first line contains an integer T, representing the number of test cases.
For each test case, the first line contains two space-separated integers N and K, denoting the size of the array and the subsequence length, respectively.
The second line contains N space-separated integers, which are the elements of the arrayNUMS
.
Output:
For each test case, print a single integer on a new line, representing the maximum sum of an increasing subsequence of length K.
Print "-1" if no such subsequence exists.
Example:
Input:
T = 1
N = 5, K = 3
NUMS = [1, 2, 5, 4, 8]
Output:
15
Constraints:
1 <= T <= 10
1 <= N <= 500
1 <= K <= N
-10^9 <= NUMS[i] <= 10^9
for eachi
- Time Limit: 1 second
Note:
- The array may contain duplicate elements.
- The array can also contain negative integers.
- Every element of the subsequence must be greater than or equal to the previous element.
- You do not need to print anything; just implement the function.
Be the first one to answer
Add answer anonymously...
Top Amdocs Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in Amdocs Associate Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app