Google Interview Question

Graph traversal and a DP question