Pergunta de entrevista da empresa Exodus

How I would solve a specific algorithm