Problem
Given array arr of size n and integer k, find the maximum sum subarray of exactly length k where all elements are distinct. Return -1 if none exists.
Source
Nedbank VAS HackerRank Assessment - Q70
Tags: Easy, Greedy, Sliding Window, Arrays
References
Constraints
- 1 <= k <= n <= 2 * 10^5
- 1 <= arr[i] <= 10^9
Example
n=6, k=3, arr=[1,2,3,7,3,5]
Output: 15 // [7,3,5]
Approach Hints
- Fixed-size window of length k
- Which data structure tracks uniqueness and frequency within the window?
- What do you do when a duplicate enters the window?
Complexity Target
Notes
Language: Java
Problem
Given array arr of size n and integer k, find the maximum sum subarray of exactly length k where all elements are distinct. Return -1 if none exists.
Source
Nedbank VAS HackerRank Assessment - Q70
Tags: Easy, Greedy, Sliding Window, Arrays
References
Constraints
Example
Approach Hints
Complexity Target
Notes
Language: Java