Prudential interview question

Solve this coding challenge using any language you prefer.