Anduril interview question

Sorting algorithm question with dp followups