Trains the technique from
LeetCode 2461Maximum Sum of Distinct Subarrays With Length KThis 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 flow meter writes one reading per minute into the log nums, oldest reading first. An auditor wants to grade a stretch of exactly k consecutive minutes.
A stretch is auditable when no reading inside it repeats, that is, all k readings in the stretch are different from one another. The score of a stretch is the sum of its k readings.
Return the largest score over all auditable stretches. If the log contains no auditable stretch at all, return 0.
Example 1
The stretch of minutes 2 through 4 holds the readings 9, 4 and 6, which are all different, and they add up to 19. No other auditable stretch of three minutes scores higher.
Example 2
Every stretch of two minutes holds the same reading twice, so no stretch is auditable and the answer is 0.
Example 3
The stretches 8,1 and 1,8 are auditable and both score 9; the stretches 8,8 are not.
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 maximum_subarray_sum(nums: list[int], k: int) -> int:public long maximumSubarraySum(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.