Domanda di colloquio di Principal Financial Group

GIven this problem, write the code to make it work (not lc style was implementation)