Pergunta de entrevista da empresa Principal Financial Group

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