Sliding Window || Java
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] findXSum(int[] nums, int k, int x) {
        List<Integer> list = new ArrayList<>();
		List<Integer> temp = new ArrayList<>();
		int start = 0;
		for (int end = 0; end < nums.length; end++) {
			temp.add(nums[end]);
			Map<Integer, Integer> map = new HashMap<>();
			if (end - start == k - 1) {
				for (Integer z : temp) {
					map.put(z, map.getOrDefault(z, 0) + 1);
				} 

				Map<Integer, Integer> sortedMap = map.entrySet().stream()
						.sorted(Map.Entry.<Integer, Integer>comparingByValue(Comparator.reverseOrder())
								.thenComparing(Map.Entry.comparingByKey(Comparator.reverseOrder())))
						.collect(Collectors.toMap(Map.Entry::getKey,          // Key
		                        Map.Entry::getValue,        // Value
		                        (e1, e2) -> e1,             // Merge function (if necessary)
		                        LinkedHashMap::new));
				
				int y = 1;
				int sum = 0;
				breakHere:
				for(Map.Entry<Integer, Integer> entry: sortedMap.entrySet()) {
					sum += entry.getKey() * entry.getValue();
					if(y == x) {
						list.add(sum);
						break breakHere;
					}

                    if(x > map.size() & y == map.size()) {
						list.add(sum);
						break breakHere;
					}
					y++;
				}
				temp.remove(0);
				start++;
				map = new HashMap<>();
			}
		}
		return list.stream().mapToInt(a-> (int)a).toArray();
    }
}
```
['Java']