Find X-Sum of All K-Long Subarrays I ->easy
Intuition\n Describe your first thoughts on how to solve this problem. \nwe have to store fre. of ele and have to do some operation as per fre and ele value\n\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe have to store fre. of ele and have to do some operation as per fre and ele value\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n.map to store ele. and fre.\n.use min heap to store fre. and ele as pair\n.if top ele. fre. is same as coming ele fre then compare ele. and put larger value ele in heap\n.simple one multiply fre. with ele. and push in vector.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N^2 + NlogX + X)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N + X + K)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> findXSum(vector<int>& nums, int k, int x) {\n        vector<int>ans;\n        int n=nums.size();\n        for(int i=0;i<n-k+1;i++){\n            map<int,int>mp;//ele. and fre.\n            for(int j=i;j<=i+k-1;j++){\n            mp[nums[j]]++;\n        }\n       priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;//min heap storing pair of fre and ele\n        for(auto ele:mp){\n          if((!pq.empty() and pq.size()>=k) and pq.top().first==ele.second){// if top ele. fre. is same as coming ele fre then compare ele. and put larger value ele in heap\n            if(pq.top().second<ele.first){\n                pq.pop();\n                // pq.push({ele.second,ele.first});\n            }\n        }\n        pq.push({ele.second,ele.first});\n        if(pq.size()>x) pq.pop();\n\n      }\n\n      int sum=0;\n      while(!pq.empty()){//simple one multiply fre. with ele. and push in vector.\n        sum+=(pq.top().first*pq.top().second);\n        pq.pop();\n      }\n     \n     ans.push_back(sum);\n        }\n      return ans;  \n    }\n};\n```
['C++']