Fixed length sliding window, frequency counter and max heap Python solution. Beats 89%
IntuitionUpdate frequency counter to reflect current window as you slide through the listApproachImplement x_sum method to take a freq_counter and current windo
# Intuition
Update frequency counter to reflect current window as you slide through the list
# Approach
Implement `x_sum` method to take a freq_counter and current window. Use max heap to get top x values. Put tuple of (frequency, value) in the max heap. There is no max heap in python so we use min heap with the values negated.

# Complexity
- Time complexity:
O(n*k) where n is length of nums and k is the max number of keys that will ever be in the frequency counter or the heap  

- Space complexity:
O(k) for the counter and the heap

# Code
```python3 []
from collections import Counter
from heapq import heapify, heappush, heappop
class Solution:
    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
        
        def x_sum(counter, arr):
            heap = []
            for k, v in counter.items():
                heappush(heap, (-v, -k))
            if len(heap)<x:
                return sum(arr)
            s = 0
            for i in range(x):
                k, v = heappop(heap)
                s+= -k * -v
            return s
        
        l = 0
        r = k
        n = len(nums)
        res = []
        counter = Counter(nums[l: r])
        res.append(x_sum(counter, nums[l:r]))
        l+=1
        while r < n:
            counter[nums[l-1]] -=1
            counter[nums[r]] +=1
            res.append(x_sum(counter, nums[l: r+1]))
            l+=1
            r+=1
        return res

        


```
['Python3']