Print tree right view

why am i failing one test case

https://ide.codingblocks.com/s/45763

https://hack.codingblocks.com/contests/c/511/950

please help me
why am i getting one wrong ans on submission

Hey Jai, your code is not able to print all the nodes on the right. To correct this you can take a variable for level and for every next level you can print the rightmost node of that level.You can check for this input
input:
55 88 28 80 89 45 30 101 -1 90 -1 56 -1 -1 -1 -1 -1 99 -1 -1 -1 -1 -1
correct output should be : 55 28 30 56 99

If still you are unable to get the idea of passing level to the function you can refer this code snippet.

void rightViewHelper(node *root, int level, int &max_level) {
	if(root == NULL) {
		return;
	}
	if(max_level<level) {
		cout<<root->data<<" ";
		max_level = level;
	}
	rightViewHelper(root->right, level+1, max_level);
	rightViewHelper(root->left, level+1, max_level);
}

void rightView(node *root) {
	int max_level = 0;
	rightViewHelper(root, 1, max_level);
}

I am also failing for this test case but it is not because of the view function. It is in the manner the tree is build.
The left child is 2i + 1 and right is 2i+2. And in other to get tree accurately to more -1 must be place before 99.
left child of 90 is 99 and index of 90 is 9 and 99 should be 19 but with the above test case it is coming out to be 17(the index of 99). Please help if there is another way for building tree. Here is my code.