Practice Maximum Sum of Almost Unique Subarray
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an integer array nums and two positive integers m and k. Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0. A subarray of nums is almost unique if it contains at least m distinct elements. A subarray is a contiguous non-empty sequence of elements within an array.
Source: Maximum Sum of Almost Unique Subarray on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,6,7,3,1,7], m = 3, k = 4
18
# Example 2
nums = [5,9,9,2,4,5,4], m = 1, k = 3
23
# Example 3
nums = [1,2,1,2,1,2,1], m = 3, k = 3
0
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Sum of Almost Unique Subarray.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.