You are given an integer array nums of length n, along with two integers k and x.
The
Count the frequency of each distinct element in the array.
Choose the top x most frequent elements. If two elements have the same frequency, the element with the greater value is preferred. If the array contains fewer than x distinct elements, choose all elements.
Compute the sum of all occurrences of the chosen elements.
Return an integer array answer of length n k answer[i] represents the nums[i..i + k - 1].
Constraints:
n nums.length
nums[i]
x k nums.length
You are given an integer array nums of length n, along with two integers k and x.
The
Count the frequency of each distinct element in the array.
Choose the top x most frequent elements. If two elements have the same frequency, the element with the greater value is preferred. If the array contains fewer than x distinct elements, choose all elements.
Compute the sum of all occurrences of the chosen elements.
Return an integer array answer of length n k answer[i] represents the nums[i..i + k - 1].
Constraints:
n nums.length
nums[i]
x k nums.length