Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of Almost Unique Subarray

med
30 min
Try to solve the Maximum Sum of Almost Unique Subarray problem.

Statement

Given an integer array nums and two positive integers m and k.

A subarray is considered almost unique if it contains at least m distinct elements.

Return the maximum sum of an almost unique subarray of length k. If no such subarray exists, return 00.

Constraints:

  • 1≤1 \leq nums.length ≤2imes104\leq 2 imes 10^4

  • 1≤1 \leq m ≤\leq k ≤\leq nums.length

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of Almost Unique Subarray

med
30 min
Try to solve the Maximum Sum of Almost Unique Subarray problem.

Statement

Given an integer array nums and two positive integers m and k.

A subarray is considered almost unique if it contains at least m distinct elements.

Return the maximum sum of an almost unique subarray of length k. If no such subarray exists, return 00.

Constraints:

  • 1≤1 \leq nums.length ≤2imes104\leq 2 imes 10^4

  • 1≤1 \leq m ≤\leq k ≤\leq nums.length

  • 1≤1 \leq nums[i] ≤109\leq 10^9