Skip to content

Practice Find X-Sum of All K-Long Subarrays I

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

Easy#3318
LeetCode Problem

Find X-Sum of All K-Long Subarrays I

Problem Statement

For every length-k window in nums, count the frequency of each value. Rank distinct values by decreasing frequency, breaking ties by larger value. Keep all occurrences of the first x ranked values and sum them; if fewer than x distinct values exist, sum the whole window. Return these sums in window order.

Source: Find X-Sum of All K-Long Subarrays I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,1,2,2,3,4,2,3], k = 6, x = 2
Output
[6,10,12]

# Example 2

Input
nums = [3,8,7,8,7,5], k = 2, x = 2
Output
[11,15,15,15,12]

Constraints

1 <= n == nums.length <= 50
1 <= nums[i] <= 50
1 <= x <= k <= nums.length

Related LeetCode Problems

Practice more problems similar to Find X-Sum of All K-Long Subarrays I.

Review your practice with PhantomCodeAI

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