Visa Inc. Interview Question

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