Comcast interview question

How would you approach coding this prompt