Didlake interview question

How would you implement the solution?