forked from DeepanshuProgrammer/GeeksforGeeks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
29 August "Problem of the Day" Answer
46 lines (42 loc) · 1.1 KB
/
29 August "Problem of the Day" Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
GeeksforGeeks
The Question is :- "Next Right Node"
Answer :-
class Solution
{
public:
Node *nextRight(Node *root, int key)
{
int ct =0;
queue<Node*> q;
if(!root)
return NULL;
q.push(root);
while(!q.empty()){
int sz = q.size();
while(sz--){
Node* temp = q.front();
q.pop();
if(ct == 1)
return temp;
if(temp -> left)
{
q.push(temp -> left);
}
if(temp -> right)
q.push(temp -> right);
if(temp -> data == key)
ct = 1;
}
if(ct == 1)
{
Node* data=new Node(-1);
return data;
}
}
return root;
//code here
}
};
Hope you understand the answer, and complete it.
Stay Connected for daily Problem of the Day answers.
Thank you All!