Pregunta de entrevista de Amazon

Leetcode easy-medium question from Tree Stack