Trains the technique from
LeetCode 689Maximum Sum of 3 Non-Overlapping SubarraysThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A support desk has an hour-by-hour record of how many calls arrived, given as nums, so nums[i] is the call count for hour i.
The rota needs three shifts, each covering exactly k consecutive hours. No hour may belong to two shifts, and the shifts are reported in the order they occur.
Return the three starting hours as a list [a, b, c] with a + k <= b and b + k <= c, chosen so that the total call count across the three shifts is as large as it can be.
Several triples may reach that largest total. In that case return the smallest triple when the three lists are compared entry by entry: the smallest a, then among those the smallest b, then among those the smallest c.
Example 1
The shifts start at hours 1, 5 and 9. Each covers two hours, hour 1 does not reach hour 5 and hour 5 does not reach hour 9, so nothing overlaps. Their call counts are 20, 4 and 20, a total of 44.
Example 2
With one-hour shifts the counts picked are 3, 3 and 3, a total of 9. Other triples also reach 9, and comparing them entry by entry makes [0, 2, 4] the smallest.
Example 3
Every hour has the same count, so any three three-hour shifts total 36. Only one arrangement fits nine hours, and it starts at 0, 3 and 6.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_sum_of_three_subarrays(nums: list[int], k: int) -> list[int]:public int[] maxSumOfThreeSubarrays(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.