forked from sknsht/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
32 lines (28 loc) · 1.03 KB
/
Solution.java
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
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = in.nextInt();
int n = in.nextInt();
HashMap<String, Integer> magazine = new HashMap<>();
for (int i = 0; i < m; i++) {
String word = in.next();
magazine.put(word, magazine.getOrDefault(word, 0) + 1);
}
HashMap<String, Integer> ransom = new HashMap<>();
for (int i = 0; i < n; i++) {
String word = in.next();
ransom.put(word, ransom.getOrDefault(word, 0) + 1);
}
in.close();
if (magazine.size() < ransom.size()) {
System.out.println("No");
} else {
Optional<Integer> res = ransom.entrySet().stream()
.map(e -> magazine.getOrDefault(e.getKey(), 0) - e.getValue())
.filter(e -> e < 0)
.findFirst();
System.out.println(res.isPresent() ? "No" : "Yes");
}
}
}