Google Interview Question

The first question is string manipulation. The second is graph.