Best Window of Distinct Numbers
Look at every stretch of exactly k consecutive items of nums in which all k numbers are different. Return the largest sum among those stretches.
If no stretch qualifies, return 0.
Example 1
nums [1,5,4,2,9,9,9]
k 3
returns 15
[4, 2, 9] has distinct items and sum 15.
Example 2
nums [4,4,4]
k 3
returns 0
No window of 3 has distinct items.
Constraints
1 <= k <= len(nums) <= 30-20 <= nums[i] <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.