My solution gives(custom input) : input: 2 123 output: 3 NULL NULL input: 4 1


#1

my solution gives(custom input) :
input:
2
123
output:
3 NULL NULL

input:
4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
output:
11 10 NULL 9 NULL NULL NULL NULL 14 13 NULL NULL 15 NULL NULL

How do I interpret this output, is it values of ‘next’ pointer my function populated?

Also,Whats 2 (single line) as an input means?It requires 3 NULL NULL as output(how?).
my function doesn’t give any output in test run. Thats impossible since even if my solution is wrong/doesn’t do anything,
original values of next i.e NULLs should be displayed.


#2

Hi Shantanu, Sorry for the confusion. The input description was incorrect.
The input is a single integer. We generate a complete tree of height H = the input and pass it to your function.

The output is the value of the next pointer for every node in inorder sequence.


#3

Anshuman Singh,thanks .That clears a lot of things!
bt what about the blank output I get on input : 2. I get corrrect outputs in custom inputs (atleast for 2 I get 3 NULL NULL).


#4

same problem as Shantanu. While submitting i am getting blank output. But for testing with custom input i am getting 3 NULL NULL for input 2


#5

Anshuman Singh If H = 3,
1
2 3
4 5 6 7

the in order traversal is:

4 2 5 1 6 3 7

and the set of next pointers are :

5 3 6 NULL 7 NULL NULL

I see this output: 4 5 6 NULL 7 NULL NULL

What am I missing?


#6

Nishant Shobhit Hey Nishant. Your interpretation is correct. Do note that the tree need not be in the same order as you mentioned.

We construct the tree using the following function :

TreeLinkNode* formCompleteTree(int depth, int &num) {
if (depth == 0) return NULL;
TreeLinkNode *root = new TreeLinkNode(num++);
root->left = formCompleteTree(depth - 1, num);
root->right = formCompleteTree(depth - 1, num);
return root;
}

As a result, the tree looks like this :

…1
…/…
…2…5
…/…/…
…3…4.6…7

Let me know if that makes sense.
I understand that the source of the confusion might have been the tree given as an example in the problem statement. I will edit the example to look like the above example. Thanks so much for pointing it out.