Pergunta de entrevista da empresa Amazon

Solve Leetcode question (leetcode medium)