Advertisement
nikunjsoni

1170

May 12th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {
  4.         int freq[12] = {0};
  5.         for(auto &word : words){
  6.             int f = getFreq(word);
  7.             freq[f]++;
  8.         }
  9.        
  10.         for(int i=10; i>=0; i--)
  11.             freq[i] += freq[i+1];
  12.        
  13.         vector<int> ans;
  14.         for(auto &query : queries)
  15.             ans.push_back(freq[getFreq(query)+1]);
  16.         return ans;
  17.     }
  18.    
  19.     int getFreq(string str){
  20.         return count(str.begin(), str.end(), *min_element(str.begin(), str.end()));
  21.     }
  22.    
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement