You are given an integer array `nums` and an integer `k`. Find the maximum subarray sum of all the subarrays of `nums` that have length `k` and whose elements are all distinct. Return that maximum, or `0` if no subarray meets the conditions.
You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that have length k and whose elements are all distinct. Return that maximum, or 0 if no subarray meets the conditions.
Example 1:
Input: {"nums":[1,5,4,2,9,9,9],"k":3}
Output: 15
Constraints:
1≤k≤nums.length≤105
1≤nums[i]≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,5,4,2,9,9,9],"k":3}
Slide a window of exactly 3 values. A hash map counts each value inside it; the window qualifies only when the map has 3 keys, meaning no value repeats.