Google Interview Question

I had to solve a problem recursively.