Pregunta de entrevista de WillowTree

It was a leetcode question.