
Asked in Google
Remove K Corner Elements - Problem Statement
Given an array "arr" consisting of "N" integer elements, your task is to remove "K" elements from the beginning or the end of the array. You must return the maximum possible sum of the remaining elements in the array.
Note: You may remove elements from both the beginning and the end, but the total number of elements removed must be exactly "K".
Input:
The first line contains a single integer ‘T’ denoting the number of test cases. Each test case includes:
1. A line containing two integers 'N' and 'K', where N is the number of elements in the array, and K is the number of elements to be removed.
2. A line containing N integers, representing the array elements arr[i].
Output:
For each test case, print a single integer denoting the maximum sum of the remaining elements of the array. The output for each test case will be printed on a separate line.
Example:
Sample Input:
2
6 3
1 2 6 4 5 3
8 4
5 3 1 1 8 8 2 2
Sample Output:
15
20
Explanation:
For test case 1: After removing two elements from the beginning and one element from the end, the array becomes {6, 4, 5}. The sum is 15.
For test case 2: After removing four elements from the beginning, the array becomes {8, 8, 2, 2}. The sum is 20.
Constraints:
- 1 <= T <= 10
- 1 <= N <= 10^4
- 0 <= K <= N
- 0 <= arr[i] <= 10^6
- Time limit: 1 sec

AnswerBot
4mo
Given an array, remove K elements from beginning or end to maximize sum of remaining elements.
Iterate through all possible combinations of removing K elements from beginning and end
Calculate sum of re...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Google
Q. What does a software developer intern do?
Q. Majority Element - II Problem Statement Given an array/list ARR of integers with...read more
Q. Consecutive Elements Given an array arr of N non-negative integers, determine wh...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Google Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

