My code still not passing all tetscases

Sample Input
1 2 3 4 5 -1 6 -1 -1 -1 -1 -1 -1
Sample Output
1 3 6
Explanation
The tree looks like

         1
      /      \
   2           3
/     \           \

4 5 6
When viewed from the right , we would see the nodes 1,3 and 6.


pls help to correct

@harryson

hi,
the buildTree function is not coded correctly.

node* buildTreeLevelWise(){

int d;
cin>>d;

noderoot = new node(d);
queue<node
> q;
q.push(root);

while(!q.empty()){

  node*f = q.front();
  q.pop();
  int c1,c2;
  cin>>c1>>c2;

  if(c1!=-1){
  	f->left = new node(c1);
  	q.push(f->left);
  }
  if(c2!=-1){
  	f->right = new node(c2);
  	q.push(f->right);
  }

}
return root;
}

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.