Tripadvisor interview question

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