
Asked in Expedia Group
Maximum Sum of Two Non-Overlapping Subarrays
Given an integer array ARR
and a positive integer K
, your objective is to find two non-overlapping subarrays (contiguous) of length K
each, such that their summed total is maximized.
Example:
Input:
ARR = [2, 5, 1, 2, 7, 3, 0]
K = 2
Output:
17
Explanation:
The optimal choice is subarrays [2, 5]
and [7, 3]
, which together yield the maximum sum of 2 + 5 + 7 + 3 = 17
.
Constraints:
- 1 <= T <= 102
- 2 <= N <= 5 * 103
- 1 <= K <= N / 2
- -105 <= ARR[i] <= 105
- The array will always have at least two non-overlapping subarrays of size
K
.
Input:
The first line consists of an integer 'T', the number of test cases.
Each test case starts with two integers 'N' and 'K', denoting the size of the array and the subarray length, respectively.
The second line contains 'N' space-separated integers indicating the elements of 'ARR'.
Output:
For each test case, output a single integer indicating the maximum obtainable sum from two non-overlapping subarrays of length 'K'.
Note:
Implement the function as specified; printing is handled separately.

AnswerBot
4mo
Find two non-overlapping subarrays of length K with maximum sum in an integer array.
Iterate through the array to find all possible subarrays of length K.
Calculate the sum of each pair of non-overlappi...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Expedia Group
Q. Knight Probability in Chessboard Calculate the probability that a knight remains...read more
Q. Remove Character from String Problem Statement Given a string str and a characte...read more
Q. Binary Tree to Doubly Linked List Transform a given Binary Tree into a Doubly Li...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Expedia Group Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development 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

