1 of 5

Dyalog APL, 22 bytes

{2⊥¨{⍵[⍋⍵]}¨↓⍉2⊥⍣¯1⊢⍵}

Try it online!