Minimum Subarray Length With Distinct Sum At Least K
You are given an integer array nums and an integer k.
Return the minimum length of a subarray whose sum of the distinct values present in that subarray, with each value counted once, is at least k. If no such subarray exists, return -1.
Example 1
Input
nums = [2,2,3,1], k = 4Output
2The subarray
[2, 3] has distinct elements {2, 3} whose sum is 2 + 3 = 5, which is at least k = 4, so the answer is 2.Example 2
Input
nums = [3,2,3,4], k = 5Output
2The subarray
[3, 2] has distinct elements {3, 2} whose sum is 3 + 2 = 5, which is at least k = 5, so the answer is 2.Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5
- 1 <= k <= 10^9