Given a binary tree of size **N **and two nodes. Your task is to complete the function **NumberOFTurn()** that should return the count of the number of turns needs to reach from one node to another node of the Binary tree.

Example:

```
Input: Below Binary Tree and two nodes
```**5** & **6 **
1
/ \
2 3
/ \ / \
4 5 6 7
/ / \
8 9 10
Output: Number of Turns needed to reach
from **5 to 6: 3**
Input: For above tree if two nodes are 1 & 4
Output: **Straight line : 0** turn

**Input:**

The function takes three arguments as input, the reference pointer to the **root** of the binary tree, second argument is the key value of the **first** node and third argument is the key value of the **second** node.

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

**Output:**

For each test case the function should return the number of turns required for going from first node to second node in the given binary tree.

**Constraints:**

1<=T<=100

1<=N<=100

**Example:
Input:**

2

2

1 2 L 1 3 R

2 3

9

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

5 10

1

4

**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.

bruceewayne | 113 |

shivam123ahuja | 98 |

BoggavarapuRamSaranSaiSrinivasGupta | 98 |

rajupraaa1234 | 95 |

SUZAKU | 92 |

mr_kksparrow | 433 |

manvirag982 | 294 |

snow_den_ | 236 |

Exception_404 | 236 |

PranathiBhuvanagiri | 232 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.