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 array NUMS.

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 each i
  • 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.
AnswerBot
4mo

Find the maximum sum of an increasing subsequence of length K in an array.

  • Iterate through the array and maintain a dynamic programming table to store the maximum sum of increasing subsequences of diff...read more

Help your peers!
Select
Add answer anonymously...

Amdocs Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 2mo agoQ. Write an SQL query to fetch records and use a join to group three tables.
An Associate Software Engineer was asked 2mo agoQ. How do you solve technical problems using recursion?
An Associate Software Engineer was asked 9mo agoQ. What is the Collection Framework in Java?

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 2mo agoQ1. Write an SQL query to fetch records and use a join to group three tables.
An Associate Software Engineer was asked 2mo agoQ2. How do you solve technical problems using recursion?
An Associate Software Engineer was asked 9mo agoQ3. What is the Collection Framework in Java?
Amdocs Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits