I have tried the code but it is giving segmentation fault

hello @Varun_a19
try running ur code for this input.
4 2
1 2 3 4

outshould be>
2 1 4 3
but urs is giving
4 3 2 1
probably u r not handling head and tail properly.
check once.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.