Right view of tree Problem(Level order input)

3 out of 4 test cases failed. Help me identifying whats wrong.

your way to create tree is wrong
this approach only work for complete binary tree
and the given tree is not complete tree

Check for this example
1 6 2 8 7 4 3 11 -1 9 -1 5 -1 -1 -1 -1 -1 10 -1 -1 -1 -1 -1
Correct output
1 2 3 5 10
but 10 will not be present in your output

Correct method to build tree

node* BuildTree() {
    int d;
    cin >> d;
    if (d == -1)return NULL;
    node* root = new node(d);
    queue<node*>q;
    q.push(root);
    while (!q.empty()) {
        node* temp = q.front();
        q.pop();
        int lc, rc;
        cin >> lc >> rc;
        if (lc != -1) {
            temp->left = new node(lc);
            q.push(temp->left);
        }
        if (rc != -1) {
            temp->right = new node(rc);
            q.push(temp->right);
        }
    }
    return root;
}

Thanks a lot. Great explanation. The test case helped me get a crystal clarity as to where my code is failing.

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.