Java - Heap - beats 96.27%
Intuition\nThere\'s really no intuition here because this is a medium problem disguised as an easy and ya\'ll are ridiculous, honestly. \n\n# Approach\n1 - you 
# Intuition\nThere\'s really no intuition here because this is a medium problem disguised as an easy and ya\'ll are ridiculous, honestly. \n\n# Approach\n1 - you need a nested for loop to iterate through the the sub arrays.  The bounds are just a little tricky, but they\'re below.  \n2 - you create a heap (priority queue) that sorts by two criteria: the number of occurrences, and then the actual number itself.  The comparator below does that for you.  \n3 - process the answer.  \n\n# Complexity\n- Time complexity:\nI\'m not sure... looks like O(n * log(n)) for the heap processing\n\n- Space complexity:\nO(n) since there\'s a heap allocated that is, at maximum, the size of nums.  It gets reclaimed continually. \n\n# Code\n```java []\nclass Solution {\n    public int[] findXSum(int[] nums, int k, int x) {\n\n        // k is the length of the answer... \n        int[] ans = new int[nums.length - k + 1];\n        for(int i = 0; i <= nums.length - k; i++) { // offset\n            int[] count = new int[51]; \n            // process:\n            for(int j = i; j < k+i; j++) {\n                count[nums[j]]++;      \n            }\n            int sum = xSum(count, x); \n            ans[i] = sum; \n        }\n        return ans;\n    }\n\n    public int xSum(int[] count, int x) {\n        PriorityQueue<int[]> heap = new PriorityQueue<>(new Comparator<int[]>() {\n            @Override public int compare(int[] a, int[] b) {\n                if(a[1] != b[1]) {\n                    return b[1] - a[1];\n                }\n                else {\n                    return b[0] - a[0];\n                }\n            }\n        }); \n        for(int i = 0; i < count.length; i++) {\n            if(count[i] > 0) {\n                heap.offer(new int[]{i, count[i]});\n            }\n        }\n\n        int sum = 0;\n        for(int i = 0; i < x && ! heap.isEmpty(); i++) {\n            int[] num = heap.poll(); \n            sum += num[0] * num[1];\n        }\n        return sum; \n    }\n}\n```
['Java']