Pregunta de entrevista de Google

Leetcode hard question on their platform