Pregunta de entrevista de Yahoo

One technical question, leetcode medium level.