Pergunta de entrevista da empresa Amazon

leetcode question. easy level. look for efficient way