✅ Simple Java Solution
CODE\nJava []\npublic int[] findXSum(int[] nums, int k, int x) {\n\tint n = nums.length;\n\tint res[] = new int[n-k+1];\n\tfor(int i=0; i<res.length; i++) {\n\t
## **CODE**\n```Java []\npublic int[] findXSum(int[] nums, int k, int x) {\n\tint n = nums.length;\n\tint res[] = new int[n-k+1];\n\tfor(int i=0; i<res.length; i++) {\n\t\tint sum = 0;\n\t\tSet<Integer> set = new HashSet<>();\n\t\tHashMap<Integer, Integer> map = new HashMap<>();\n\t\tfor(int j=i; j < i+k; j++) {\n\t\t\tsum += nums[j];\n\t\t\tset.add(nums[j]);\n\t\t\tmap.put(nums[j], map.getOrDefault(nums[j], 0) + 1);\n\t\t}\n\n\t\tif(set.size() < x) res[i] = sum;\n\t\telse {\n\t\t\tPriorityQueue<Integer> pq = new PriorityQueue<>((a,b) -> {\n\t\t\t\tif(map.get(a) == map.get(b)) return b-a;\n\t\t\t\treturn map.get(b)-map.get(a);\n\t\t\t});\n\t\t\tfor(int ele : set) pq.add(ele);\n\t\t\tint ct = x;\n\t\t\twhile(ct-- > 0) {\n\t\t\t\tint top = pq.remove();\n\t\t\t\tres[i] += (top*map.get(top));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn res;\n}\n```
['Java']