Given a binary tree, your task is to complete the function **findRightSibling(), **that should return** **the right sibling to a given node if it doesn’t exist return **null**.

```
Structure of the node of the binary tree is as
struct Node
{
int data;
Node* left;
Node* right;
Node* parent;
};
```

Examples:

```
1
/ \
2 3
/ \ \
4 6 5
/ \ \
7 9 8
/ \
10 12
Input : Given above tree with parent pointer and node 10
Output : 12
```

**Input:**

The function takes a single argument as input, the reference pointer to the **node** whose right sibling is to be found in the provided binary tree.

There will be **T**, test cases and for each test case, the function will be called separately.

**Output:**

For each test case return the pointer to the right sibling of a given node.

**Constraints:**

1<=T<=100

1<=N<=100

**Example:
Input:**

2

10

1 2 L 1 3 R 2 4 L 2 6 R 4 7 L 7 10 L 6 9 R 9 12 R 3 5 R 5 8 R

7

2

1 2 L 1 3 R

2

9

3

**Note:**The **Input/Ouput** format and **Example** given are used for system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.