Pregunta de entrevista de Visa Inc.

I create a recursive for loop and then optimized the solution using a dictionary