Comcast Interview Question

How would you approach coding this prompt