Pregunta de entrevista de Google

It is like a leetcode question