Pergunta de entrevista da empresa Applied Intuition

Coding question with hard LC difficulty