Pergunta de entrevista da empresa Google

It is like a leetcode question