Google Interview Question

its graph question. topological sort