Pregunta de entrevista de Amazon

Coding question was a leetcode hard question