Solution for a Supermarket coding challenge