Pregunta de entrevista de Amazon

Leetcode medium or easy level difficulty.