Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of Almost Unique Subarray

Maximum Sum of Almost Unique Subarray asks you to examine fixed-length subarrays, keeping those with at least the required number of distinct values and returning the greatest sum, or zero if none qualify.

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

Maximum Sum of Almost Unique Subarray asks you to examine fixed-length subarrays, keeping those with at least the required number of distinct values and returning the greatest sum, or zero if none qualify.

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