X interview question

A graph related algorithm question