New update is available. Click here to update.

Last Updated: 25 Jun, 2021

Difficulty: Hard

```
N = 4
Edges = [2 3], [4 3], [1 3]
Output: 2
Here node 4 is at a distance 2 from node 1 and if we make node 1 as a root, it will give the height of 2, which is the maximum possible in this tree.
```

```
The first line contains a single integer 'T' denoting the number of test cases to be run. Then the test cases follow.
The first line of each test contains integer 'N' denoting the number of nodes in the tree, and the following N-1 lines contain two nodes each.
```

```
For each test case, print an integer denoting the tree's maximum height when we consider any arbitrary node as a root.
```

```
You are not required to print anything; it has already been taken care of. Just implement the function.
```

```
1 <= T <= 50
1 <= N <= 10^4
Time Limit: 1 sec.
```

SIMILAR PROBLEMS

Capturing Grid

Posted: 14 Sep, 2022

Difficulty: Moderate

Rotting Oranges

Posted: 15 Sep, 2022

Difficulty: Moderate

Distance to a Cycle in Undirected Graph

Posted: 7 Nov, 2022

Difficulty: Moderate

Randomly Sorted

Posted: 13 Nov, 2022

Difficulty: Moderate

8-Queen Problem

Posted: 19 Dec, 2022

Difficulty: Easy

Popular Interview Problems: