You are viewing a single comment's thread. Return to all comments →
Hi, your code is not giving any output for this following input...
The tree you give, is not a tree:
So we can assume that this input won't appear as one of the test cases.
sorry i didn't get you....
1 is the root,
1st 2 is left child of 1 and 2nd 2 is the right child of 1,
1st 3 is the left child of 1st 2 and right child of 1st 2 is null,
2nd 3 is the right child of 2nd 2 and left child of 2nd 2 is null,
both children of both 3 will be null....
this is the tree right.......
and i don't understand why you mentioned that both left and right child of node 1 are 2.....yeah...i can be right....since it is a binary tree not a binary search tree....and there no such rule that there shouldn't be duplicate nodes....and both the children are greater than their parent....
The 4th line of input is -1 3, which shows the left and right child of node 3. Nodes start from 1. So there is a cycle 3 -> 3. Therefore it is not a tree.
that fourth line of input are children of the right child of root node right....not the children of 3....
Uhm, no... Check the input format. It explains it quite well.
It's a tree but with nodes that have duplicate data.
In this case, swapNodes won't change the nature of the tree.
it is not mentioned in the problem.....or in the input conditions........
There is no data (well, you could say node's own index is its payload). It's just a bunch of indexes. So the root has node number 2 as a left child and also a right child. And node number three has itself as a right child.
Not a tree. Somebody just doesn't understand the format. Which really isn't surprising given the poor description.
But if anyone wants it blow by blow: