Etsy Interview Question

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