Pregunta de entrevista de Amazon

Two questions at Leetcode medium difficulty