Pregunta de entrevista de Amazon

The code question is leetcode 136