Given a special binary tree of size **N**, whose leaf nodes are connected to form a circular doubly linked list, your task is to complete the function **findTreeHeight()**, that should return the height of the tree.

For Example:

1

/ \

2 3

/ \

4 5

/

6

In the above binary tree, 6, 5 and 3 are leaf nodes and they form a circular doubly linked list. Here, the left pointer of leaf node will act as a previous pointer of circular doubly linked list and its right pointer will act as next pointer of circular doubly linked list.

**Input:**

The first line of input contains **T**, denoting the number of testcases. Each testcase contains one line i.e. N(number of edges).

**Output:**

For each testcase in new line, print the height of spiral tree.

**User Task:**

Since this is a functional problem you don't have to worry about input, you just have to complete the function **findTreeHeight()**.

**Constraints:**

1 <= T <= 76

1 <= N <= 300

**Example:
Input:**

2

3

1 2 L 1 3 R 2 4 L

5

1 2 L 1 3 R 2 4 L 2 5 R 4 6 L

**Output:**

3

4

**Explanation:
Testcase 1:** There are 3 edges and 4 nodes in spiral tree where leaf nodes 4 and 3 are connected in circular doubly linked list form. Thus the height of spiral tree is 3.

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.

hari32147 | 206 |

preparecodinginterview_dot_com | 190 |

JonSnow_IKnowNothing | 168 |

shivamsingh00236 | 130 |

AdityaRaj9 | 121 |

abducodes | 906 |

harshtyagi36 | 447 |

arpit_anshuman | 347 |

vaibhavarya16221 | 333 |

vamsikrishna55 | 323 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.