-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[Others]ContactTracing.java
52 lines (43 loc) · 1.76 KB
/
[Others]ContactTracing.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Wong Kai Min Herman
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner s = new Scanner(System.in);
int maxCount = 0;
Map<Integer,Set<Integer>> map = new HashMap();
while (s.hasNextLine()) {
String line = s.nextLine();
if(line.equals("Q1")){
System.out.println(maxCount);
}
else{
String[] numArray = line.split("-");
int firstNum = Integer.parseInt(numArray[0]);
int secondNum = Integer.parseInt(numArray[1]);
if(map.containsKey(firstNum)){
map.get(firstNum).add(secondNum);
maxCount = Math.max(maxCount,map.get(firstNum).size());
}else{
Set<Integer> set = new HashSet();
set.add(secondNum);
map.put(firstNum, set);
maxCount = Math.max(maxCount,map.get(firstNum).size());
}
if(map.containsKey(secondNum)){
map.get(secondNum).add(firstNum);
maxCount = Math.max(maxCount,map.get(secondNum).size());
}else{
Set<Integer> set = new HashSet();
set.add(firstNum);
map.put(secondNum, set);
maxCount = Math.max(maxCount,map.get(secondNum).size());
}
}
}
}
}