static class Solution {
public Node solveFor(String[] room) {
Graph graph = Graph.fromStringArray(room);
List<Node> specialNodes = graph.getSpecialNodes();
Set<Node> nodes = graph.getAllNodes();
BFS bfs = new BFS(graph);
int previousMinDistance = Integer.MAX_VALUE;
Node bestNodeSoFar = null;
for (Node node : nodes) {
if (specialNodes.contains(node)) {
continue;
}
int localDistance = 0;
for (Node stationNode : specialNodes) {
localDistance += bfs.distanceFrom(stationNode, node);
}
if (localDistance < previousMinDistance) {
previousMinDistance = localDistance;
bestNodeSoFar = node;
}