Question d’entretien chez Principal Financial Group

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