Etsy interview question

How would you design this algorithm that we use at work>