Domanda di colloquio di Amazon

leetcode looking question but slightly harder