We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The swapping part of the question was actually simple. Getting the input and converting into the tree was actually a bit tedious because of the way the input was given.
Actual swapping could be done just with a simple addition to normal inorder traversal once the tree was built(which required queue, to simplify the process of creating it.)
Here's my swap function. Hope it helps in understanding the problem for anyone who actually found swapping ambiguous:
Swap Nodes [Algo]
You are viewing a single comment's thread. Return to all comments →
The swapping part of the question was actually simple. Getting the input and converting into the tree was actually a bit tedious because of the way the input was given. Actual swapping could be done just with a simple addition to normal inorder traversal once the tree was built(which required queue, to simplify the process of creating it.) Here's my swap function. Hope it helps in understanding the problem for anyone who actually found swapping ambiguous: