Tesco Interview Question

Coding round looking for complete working solution