LTM Limited Interview Question

Coding based question of swapping