Pergunta de entrevista da empresa Etsy

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