Hudson River Trading Interview Question

Typical leer code BFS/DFS question.