Anduril Interview Question

Sorting algorithm question with dp followups