Playment interview question

Solve the given problem using a language of your choice