Reverse alternae levels


please explain their 3rd method with single traversal

hi @ayu2321 they are recursively swapping the left and right subtrees, which eventually results in the level being reversed. Do a dry run once, for better understanding

i have one doubt
in the question it is asked that v hav to reverse the nodes at alternate level…i-e if we strt frm 0 then we have to reverse it for level 1 which is an odd level but in that algorithm why are the swapping for even level although they are starting from 0

@ayu2321 Its hard to explain without the dry run. But if you do lvl%2 != 0 You will see that actually the even levels are getting reversed, Do a dry run of the code and let me know if you have any trouble doing that

can you please help me to dry run this code

hi @ayu2321 are you getting stuck anywhere? If so please tell me so I can help you in a better manner.

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.