-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1152.cpp
More file actions
44 lines (40 loc) · 1.51 KB
/
1152.cpp
File metadata and controls
44 lines (40 loc) · 1.51 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solution {
public:
vector<string> mostVisitedPattern(vector<string>& username, vector<int>& timestamp, vector<string>& website) {
int n = username.size();
unordered_map<string, map<int, string>> mp; // name->{time, web}
int maxFreq = 0;
unordered_map<string, int> freq;
for (int i = 0; i < n; i++) {
mp[username[i]][timestamp[i]] = website[i];
}
for (auto element : mp) {
map<int, string> userData = element.second;
unordered_set<string> st;
for (auto i = userData.begin(); i != userData.end(); i++) {
for (auto j = next(i); j != userData.end(); j++) {
for (auto k = next(j); k != userData.end(); k++) {
string hashing = i->second + " " + j->second + " " + k->second;
st.insert(hashing);
}
}
}
for (auto pattern : st) {
freq[pattern]++;
maxFreq = max(maxFreq, freq[pattern]);
}
}
string res = "";
for (auto element : freq) {
if (element.second == maxFreq) {
if (res.size() == 0) res = element.first;
else if (element.first < res) res = element.first;
}
}
string token;
stringstream ss(res);
vector<string> ans;
while (getline(ss, token, ' ')) ans.push_back(token);
return ans;
}
};