-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparseArray.js
More file actions
61 lines (43 loc) · 1.31 KB
/
Copy pathsparseArray.js
File metadata and controls
61 lines (43 loc) · 1.31 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in
// the list of input strings. Return an array of the results.
// Function Description
// Complete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in strings.
// matchingStrings has the following parameters:
// string strings[n] - an array of strings to search
// string queries[q] - an array of query strings
// Returns
// int[q]: an array of results for each query
// Input Format
// The first line contains and integer , the size of .
// Each of the next lines contains a string .
// The next line contains , the size of .
// Each of the next lines contains a string .
// Sample Input 1
// 4
// aba
// baba
// aba
// xzxb
// 3
// aba
// xzxb
// ab
// Sample Output 1
// 2
// 1
// 0
function matchingStrings(strings, queries) {
// Write your code here
let [count, results] = [0, []];
queries.forEach((query) => {
count = 0;
strings.forEach((singleString) => {
if (singleString === query) {
count += 1;
}
});
results.push(count);
});
return results;
}
matchingStrings(["aba", "baba", "aba", "xzxb"], ["aba", "xzxb", "ab"]);