forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathM0001.cpp
More file actions
36 lines (32 loc) · 753 Bytes
/
M0001.cpp
File metadata and controls
36 lines (32 loc) · 753 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
30
31
32
33
34
35
36
/*
Problem Code: https://www.hackerrank.com/challenges/sparse-arrays/problem
*/
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
vector<int> matchingStrings(vector<string> &strings, vector<string> &queries) {
vector<int> freq;
unordered_map<string, int> map;
for (auto s: strings)
map[s]++;
for (auto q: queries)
freq.push_back(map[q]);
return freq;
}
int main() {
int n, q;
cin >> n;
vector<string> strings(n);
for (int i = 0; i < n; i++)
cin >> strings[i];
cin >> q;
vector<string> queries(q);
for (int i = 0; i < q; i++)
cin >> queries[i];
vector<int> freq = matchingStrings(strings, queries);
for (int i = 0; i < freq.size(); i++)
cout << freq[i] << endl;
return 0;
}