Skip to content

Latest commit

 

History

History
 
 

max-sum-k-non-adjacent

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README

This isn't a HackerRank challenge - just something I wanted to try.

Problem

Find the sum of the top K non-adjacent integers in a list.

Input Format

The first line contains a single integer T, the number of test cases. For every test case, the first line contains a single integer N, where N is the size of the list. The next line contains a single integer K. The following line contains N integers {a1, a2 ... aN}.

You can execute python3 generator.py to create some random input data.

Constraints

0 <= T <= 232 - 1

0 <= N <= 232 - 1

0 < K <= N

0 <= ai <= 232 - 1

Output Format

For each test case, print the sum of the top K non-adjacent integers of the list or -1 if it is not possible to pick K non-adjacent integers.

Sample Input

1
5
3
1 2 3 4 5

Sample Output

9

Explanation

5 + 3 + 1 = 9