Google interview question

A tough programming question related directed graph