Sort nearly sorted k array