Bloomberg Interview Question

gave a puzzle to solve and asked to programme it