Atlassian interview question

A easy-medium problem involving DFS.