aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/deadmarshal/java/Ch1.java
blob: 8b8f8229f4e5c09b33b5574c148a7fb3e906b199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.HashMap;
import java.util.Map;

public class Ch1 {
  public static void main(String[] args) {
    String[][] arr1 = {{"B", "C"}, {"D", "B"}, {"C", "A"}};
    String[][] arr2 = {{"A", "Z"}};
    System.out.println(no_connection(arr1));
    System.out.println(no_connection(arr2));
  }

  private static String no_connection(String[][] arr) {
    Map<String, Integer> destinations = new HashMap<>(),
      sources = new HashMap<>();
    for (String[] a : arr) {
      sources.put(a[0], 1);
      destinations.put(a[1], 1);
    }
    for (String d : destinations.keySet())
      if (!sources.containsKey(d)) return d;
    return "";
  }
}