Python3 O(N ^ 2 log N) Solution with a hash table (97.32% Runtime)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n\n# Approach\n Describe your approach to solving the problem. \n- Iterate through t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n![image.png](https://assets.leetcode.com/users/images/412ee493-7609-45f0-81fc-7ba63071b5df_1730510764.429047.png)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Iterate through the given array with frequency counting via defaultdict.\n- Sort the temporal array from the defaultdict and compute x sum.\n\n# Complexity\n- Time complexity: O(N ^ 2) (n * k * sorting)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N) (defaultdict)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\nIf this solution is similar to yours or helpful, upvote me if you don\'t mind\n```python3 []\nclass Solution:\n    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:\n        ans=[]\n        for i in range(len(nums)-k+1):\n            a=0\n            d=defaultdict(int)\n            for n in nums[i:i+k]:\n                d[n]+=1\n\n            t=[y for y in d.items()]\n            t.sort(key=lambda y: (-y[1],-y[0]))\n\n            m=0\n            for key,val in t:\n                if m==x:\n                    break\n                a+=key*val\n                m+=1\n            ans.append(a)\n        return ans\n```
['Array', 'Hash Table', 'Sorting', 'Python', 'Python3']