Hudson River Trading interview question

Typical leer code BFS/DFS question.