Question d’entretien chez Google

island quesiton on leetcode - medium difficulty