All Problems

Problem title

Difficulty

Avg time to solve

Z Algorithm

Hard

15 mins

Implement Deque

Easy

15 mins

Single Number

Easy

10 mins

Bellman Ford

Moderate

30 mins

Print All Subsets

Easy

20 mins

Remove K Corner Elements

Easy

15 mins

Min Heap

Moderate

30 mins

MergeSort Linked List

Moderate

30 mins

Last Appearance

Moderate

38 mins

Odd even level

Easy

20 mins

Problem

Submissions

16

Avg. time to solve

15 min

Success Rate

80%

Problem Statement

```
If N = 7 and K = 3, and the input array is:
{1, 2, 3, 4, 5, 6, 7}
After removing the first three elements, the resulting array now becomes {4, 5, 6, 7} and the sum of the remaining array is equal to 22.
Removing any other combination of three elements will always result in the remaining array sum less than 22.
```

```
The first line contains a single integer ‘T’ denoting the number of test cases. Then each test case follows.
The first line of each test case contains two integers ‘N’ and ‘K’, where N denotes the length of the given array and K denotes the number of elements to be removed.
The next line of each test case contains N integers denoting array elements ‘arr[i]’.
```

```
For each test case print a single integer denoting the maximum sum of the remaining array.
Output for each test case will be printed in a separate line.
```

```
You are not required to print anything; it has already been taken care of. Just implement the function.
```

```
1 <= T <= 10
1 <= N <= 10^4
0 <= K <= N
0 <= arr[i] <=10^6
Time limit: 1 sec
```

```
2
6 3
1 2 6 4 5 3
8 4
5 3 1 1 8 8 2 2
```

```
15
20
```

```
For test case 1 :
After removing two elements from the beginning and one element from the end, the original array now becomes {6, 4, 5}. The remaining elements of the array have a sum equal to 15.
For test case 2 :
After removing four elements from the beginning, the original array now becomes {8, 8, 2, 2}. The remaining elements of the array have a sum equal to 20.
```

```
2
5 5
4 5 7 2 3
5 0
1 2 3 4 5
```

```
0
15
```

Java (SE 1.8)

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Full Screen Mode

Change Theme

Solution submission not allowed

Save Code

Reset Code