Question d’entretien chez Amazon

A Question on Data Structures (Hash Map) which i had to code with optimal time and space complexity.