Pregunta de entrevista de Tesco

Coding round looking for complete working solution