Simple 2 Approach Hash Table & Sliding Window 
Complexity
Time complexity:
O(n*k)
Space complexity:
O(n)CodeComplexity
Time complexity:
O(n)
Space complexity:
O(n)Code
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n*k)
----
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)
----
# Code
```cpp []
class Solution {
public:
    vector<int> findXSum(vector<int>& nums, int k, int x) {
        vector<int>ans;
        for(int l=0; l+k<=nums.size(); l++){
            vector<int>frq(51);
            vector<int>frqOfFrq(51);
            for(int r=l; r<l+k; r++){
                frq[nums[r]]++;
                frqOfFrq[frq[nums[r]]]++;
            }
            int tmp=0, cnt=x;
            for(int i=50; cnt>0 && i>=0; i--){
                if(!frqOfFrq[i]) continue;
                for(int j=50; cnt>0 && j>=0; j--){
                    if(frq[j]==i){
                        tmp +=(j*frq[j]); cnt--;
                    }
                }
            }
            ans.push_back(tmp);
        }
        return ans;
    }
};
```
```java []
class Solution {
    public int[] findXSum(int[] nums, int k, int x) {
        int[]ans = new int [nums.length-k+1];
        int idx=0;
        for(int l=0; l+k<=nums.length; l++){
           int[]frq = new int [51];
           int[]frqOfFrq = new int [51];
           for(int r=l; r<l+k; r++){
                frq[nums[r]]++;
                frqOfFrq[frq[nums[r]]]++;
            }
            int tmp=0, cnt=x;
            for(int i=50; cnt>0 && i>=0; i--){
                if(frqOfFrq[i]==0) continue;
                for(int j=50; cnt>0 && j>=0; j--){
                    if(frq[j]==i){
                        tmp +=(j*frq[j]); cnt--;
                    }
                }
            }
            ans[idx++] = tmp;
        }
        return ans;
    }
}
```
---------
                        -- Optimization sliding Window --
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
----
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)
----
# Code
```cpp []
class Solution {
public:
    vector<int> findXSum(vector<int>& nums, int k, int x) {
        vector<int>ans;
        int l=0, r=0;
        vector<int>frq(51), frqOfFrq(51);
        while(l<=nums.size()-k){
            while(r<l+k){
                frq[nums[r]]++;
                frqOfFrq[frq[nums[r]]]++;
                r++;
            }
            int tmp=0, cnt=x;
            for(int i=50; cnt>0 && i>=0; i--){
                if(!frqOfFrq[i]) continue;
                for(int j=50; cnt>0 && j>=0; j--){
                    if(frq[j]==i){
                        tmp +=(j*frq[j]); cnt--;
                    }
                }
            }
            ans.push_back(tmp);
            frqOfFrq[frq[nums[l]]]--;
            frq[nums[l]]--;
            l++;
        }
        return ans;
    }
};
```
```java []
class Solution {
    public int[] findXSum(int[] nums, int k, int x) {
        int[]ans = new int [nums.length-k+1]; 
        int[]frq = new int [51];
        int[]frqOfFrq = new int [51];
        int l=0, r=0, idx=0;
        while(l<=nums.length-k){
            while(r<l+k){
                frq[nums[r]]++;
                frqOfFrq[frq[nums[r]]]++;
                r++;
            }
            int tmp=0, cnt=x;
            for(int i=50; cnt>0 && i>=0; i--){
                if(frqOfFrq[i]==0) continue;
                for(int j=50; cnt>0 && j>=0; j--){
                    if(frq[j]==i){
                        tmp +=(j*frq[j]); cnt--;
                    }
                }
            }
            ans[idx++] = tmp;
            frqOfFrq[frq[nums[l]]]--;
            frq[nums[l]]--;
            l++;
        }
        return ans;
    }
}
```
['Array', 'Hash Table', 'Sliding Window', 'C++', 'Java']