Associated Course(s):
Sudo Placement 2019

Given a Binary Heap of size **N**, write a program to calculate the height of the Heap.

**Input:**

First line of the input contains an integer **T**, denoting the number of test cases. Then **T** test case follows. The first line of each test case contains an integer **N** denoting the number of node in the Heap. Next line contains N space separated integers denoting the elements of the heap.

**Output:**

For each test case print the height of the Heap on a new line.

**Constraints:**

1<=T<=100

1<=N<=10^{3}

**Example:
Input:**

2

6

1 3 6 5 9 8

9

3 6 9 2 15 10 14 5 12

2

3

Testcase 1:

```
Input : N = 6
Output : 2
(1)
/ \
(3) (6)
/ \ /
(5) (9) (8)
```

**Testcase 2:**

```
Input : N = 9
Output :
(2)
/ \
(3) (9)
/ \ / \
(5) (15) (10) (14)
/ \
(6) (12)
```

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.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

Ashish Kumar Vaishy | 114 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.