Marks & Spencer interview question

Solve a medium difficulty coding challenge