
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Problem Statement
Given an array of integers nums and an integer k, find the starting indices of three non-overlapping subarrays having maximum sum and each of a length k.
Return the array of size 3 containing the starting indices of such subarrays. If multiple answers exist, return the lexicographically smallest answer.
Examples
Example 1:
- Input:
nums = [1, 2, 3, 1, 1, 2, 1, 3, 2], k = 2 - Expected Output:
[1, 4, 7] - Justification: The subarrays would be
[2, 3],[1, 2], and[3, 2]with sums 5, 3, and 5 respectively.
Example 2:
- Input:
nums = [4, 5, 10, 6, 11, 17, 4, 5, 6, 7], k = 3 - Expected Output:
[0, 3, 7] - Justification: The subarrays would be
[4, 5, 10],[6, 11, 17], and[5, 6, 7]with sums 19, 34, and 18 respectively.
Example 3:
- Input:
nums = [1, 1, 1, 1, 1, 1, 1, 1, 1], k = 2 - Expected Output:
[0, 2, 4] - Justification: The subarrays would be
[1, 1],[1, 1], and[1, 1]with each having a sum of 2.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory