Pergunta de entrevista da empresa Amazon

Two questions at Leetcode medium difficulty