sales[i] is the product id sold on day i (its value is also its revenue). Among all windows of exactly k consecutive days where all values are distinct, return the maximum sum. Return 0 if none exist.
Signature
maxDistinctWindow(sales: int[], k: int) → intExample 1
sales = [1,5,4,2,9,9,9]
k = 3
output = 15
[5,4,2]=11, [4,2,9]=15 ← best; windows with repeated 9s don't count
Example 2
sales = [4,4,4]
k = 3
output = 0
no window has distinct values → 0
Constraints
1 ≤ k ≤ n ≤ 10^51 ≤ sales[i] ≤ 10^5
⌘/Ctrl + Enter runs examples
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).