Skip to content

Practice Maximum Sum of Distinct Subarrays With Length K

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2461
LeetCode Problem

Maximum Sum of Distinct Subarrays With Length K

Problem Statement

Among contiguous subarrays of nums with exactly k entries and no repeated values, return the largest sum. Return 0 when no subarray qualifies.

Source: Maximum Sum of Distinct Subarrays With Length K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,5,4,2,9,9,9], k = 3
Output
15

# Example 2

Input
nums = [4,4,4], k = 3
Output
0

Constraints

1 <= k <= nums.length <= 10^5
1 <= nums[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Maximum Sum of Distinct Subarrays With Length K.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.