
Asked in Symphony Talent
Height of Binary Tree
You are provided with the Inorder and Level Order traversals of a Binary Tree composed of integers. Your goal is to determine the height of this Binary Tree without actually constructing it.
The height of a Binary Tree is defined as the number of edges on the longest path from the root node to any leaf node. If the tree consists of only a single node, the height is considered to be 0.
Input:
Input begins with an integer ‘T’ denoting the number of test cases. Each test case includes the following: 1. An integer ‘N’ indicating the number of nodes in the binary tree. 2. ‘N’ integers representing the Inorder traversal of the binary tree. 3. ‘N’ integers representing the Level Order traversal of the binary tree.
Output:
The height of the binary tree should be printed for each test case separately. Each height is printed on a new line.
Example:
Input:
T = 1
N = 3
Inorder Traversal = 2 1 3
Level Order Traversal = 1 2 3
Output:
1
Constraints:
- 1 <= T <= 100
- 1 <= N <= 3000
- 1 <= inorder[i] <= N
- 1 <= levelOrder[i] <= N
Note: You are not required to print anything as this has been managed; implement the function to return the result.

AnswerBot
4mo
Find the height of a Binary Tree given its Inorder and Level Order traversals without constructing it.
Use the properties of Inorder and Level Order traversals to determine the height of the Binary Tre...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Symphony Talent
Q. Matrix Symmetry Check Problem Statement You are provided with a square matrix. Y...read more
Q. Cycle Detection in a Singly Linked List Determine if a given singly linked list ...read more
Q. Merge Sort Linked List Problem Statement You are given a singly linked list of i...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Symphony Talent Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software 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

