Pregunta de entrevista de Anduril

Sorting algorithm question with dp followups