Google Interview Question: Chain of strings