Maximum Sum of Distinct Subarrays With Length K

Medium · Arrays & Strings · about 15 minutes

Asked at Amazon, Bloomberg, Google, Meta, Microsoft.

Return the maximum sum of a contiguous subarray of nums with length exactly k and all elements distinct, or 0 if no such subarray exists. The answer may exceed 32 bits in general; here it fits in a 32-bit signed integer.

Related guides