Pregunta de entrevista de Google

I received a Leetcode style question.