Pregunta de entrevista de Amazon

I cannot remember but it was LeetCode easy-medium