Pergunta de entrevista da empresa monday.com

Some complexity question in which first I had to solve then reduce my solutions' complexity