Pergunta de entrevista da empresa Lemon.io

Difficult algorithmic technical exercise that I had to figure out in a very short time.