Given an array nums of positive integers, find the maximum sum of a subarray with all unique elements.
Sliding window with a HashSet to track unique elements in current window. When a duplicate is found, shrink the window from the left.
- Maintain left pointer, running sum, and a HashSet of current window elements.
- Expand right: if nums[right] already in set, remove nums[left] and advance left (repeat).
- Add nums[right] to set and sum.
- Track maximum sum.
- Time Complexity: O(N)
- Space Complexity: O(N) — HashSet