#3795

Minimum Subarray Length With Distinct Sum At Least K

expert · 1110 · lc medium +32 · 31.6% accepted · 76 likes · top 9%

Description

Given an integer array nums and an integer k, find the shortest subarray such that the sum of its distinct values (each unique value counted only once) is at least k, and return its length — or -1 if no such subarray exists.

Code

1
2
3