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!
Select
Add answer anonymously...

PolicyBazaar Software Developer interview questions & answers

A Software Developer was asked 6mo agoQ. Tell me about yourself.
A Software Developer was asked Q. Nth Fibonacci Number Problem Statement Calculate the Nth term in the Fibonacci s...read more
A Software Developer was asked Q. Right View of Binary Tree Given a binary tree of integers, your task is to outpu...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. Tell me about yourself.
A Software Developer was asked Q2. Nth Fibonacci Number Problem Statement Calculate the Nth term in the Fibonacci s...read more
A Software Developer was asked Q3. Right View of Binary Tree Given a binary tree of integers, your task is to outpu...read more
PolicyBazaar Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits