Pregunta de entrevista de Prudential

Solve this coding challenge using any language you prefer.