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.

msriramvarma01 | 25 |

AbhilashKumar2 | 24 |

monusinghal | 24 |

tripurari_IT | 24 |

Abreez Das | 23 |

ARUN_PUNDIR | 609 |

manishgupta8497 | 607 |

KhyatiSoneji | 501 |

Abhimanyu_kumar | 487 |

vvggfggcg | 453 |

blackshadows | 5333 |

Ibrahim Nash | 5221 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.