-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem-1170.cpp
More file actions
29 lines (25 loc) · 775 Bytes
/
Problem-1170.cpp
File metadata and controls
29 lines (25 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Problem - 1170
// https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/
// Passes all test cases O(nlogn) time complexity
class Solution {
public:
int fun(string s) {
map <char, int> m;
for(char c : s)
m[c]++;
return m.begin()->second;
}
vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {
vector <int> ans(queries.size());
multiset <int> st;
for(auto s : words) {
if(s.length())
st.insert(fun(s));
}
for(int i = 0; i < queries.size(); i++) {
int num = fun(queries[i]);
ans[i] = distance(st.upper_bound(num), st.end());
}
return ans;
}
};