LTM Limited interview question

Coding based question of swapping