Google Interview Question

A tough programming question related directed graph