
Asked in Intuit
Binary Tree Diameter Problem Statement
You are given a Binary Tree, and you need to determine the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any two end nodes in the tree.
Input:
The first line contains an integer 'T', representing the number of test cases. Each test case consists of a single line listing the tree nodes in level order, with nodes separated by spaces. Use -1 to denote a null node.
Output:
For each test case, output a single integer representing the diameter of the binary tree. Each result should be printed on a new line.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
6
Explanation:
The provided input represents a binary tree. The nodes contributing to the diameter are highlighted, and the length of the path between them is 6.
Constraints:
1 ≤ T ≤ 10
0 ≤ N ≤ 105
1 ≤ data ≤ 104
Where ‘N’ is the total number of nodes in the binary tree, and 'data' represents the node values.
Note: You are not required to handle input/output operations. Implement the function to compute the result.
Be the first one to answer
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Intuit
Q. How do you debug C++ code?
Q. What is polymorphism?
Q. Rearrange Linked List Problem Statement Given a singly linked list in the form '...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Intuit Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 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

