Pregunta de entrevista de Booking.com

Sorting algorithm as the question