Question d’entretien chez Tripadvisor

a tipical leetcode question. Sort the array with some other conditions