Height of a Binary Tree
You are provided with an arbitrary binary tree consisting of 'N' nodes where each node is associated with a certain value. The task is to determine the height of the tree.
Explanation:
The height of a binary tree is defined as the maximum number of edges from the root to any of its leaf nodes.
Input:
The first line consists of an integer T, representing the number of test cases.
The first line of each test case contains the values of the nodes in the binary tree in level order (use -1 to represent a NULL node).
Output:
For each test case, output the height of the binary tree as a single integer.
Example:
Input:
1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1
Output:
4
Constraints:
- 1 <= T <= 5
- 1 <= N <= 3000
- Time Limit: 1 sec
Note:
There is no need to print anything explicitly; you only need to implement the function to solve the problem.

AnswerBot
1y
The height of a binary tree is the maximum number of edges from the root to a leaf node.
Traverse the tree recursively and keep track of the maximum height
If the current node is null, return 0
Otherwise...read more
Help your peers!
Add answer anonymously...
Top Associate Software Engineer Interview Questions Asked at Publicis Sapient
Q. Where are the job locations of Publicis Sapient in India?
Q. What is Event loop? What is higher order components?
Q. Merge Two Sorted Arrays Problem Statement Given two sorted integer arrays ARR1 a...read more
Interview Questions Asked to Associate Software Engineer at Other Companies
Top Skill-Based Questions for Publicis Sapient Associate Software Engineer
C++ Interview Questions and Answers
300 Questions
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

