Binary Tree Diameter Problem Statement
Given a binary tree, determine the length of its diameter. The diameter is defined as the longest path between any two end nodes in the tree. The path's length is represented by the number of edges between these nodes.
Example:
Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
6
Explanation:
For the provided binary tree, the longest path between two leaf nodes results in a diameter length of 6. Nodes in this path have been highlighted.
Constraints:
1 <= T <= 10
0 <= N <= 105
1 <= data <= 104
- The time limit is 1 second.

AnswerBot
4mo
The diameter of a binary tree is the longest path between any two end nodes in the tree.
Traverse the tree to find the longest path between two leaf nodes.
Use depth-first search (DFS) to calculate the ...read more
Help your peers!
Add answer anonymously...
Paytm Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Find All Pairs Adding Up to Target Given an array of integers ARR of length N an...read more
A Software Developer Intern was asked Q. Binary Tree Diameter Problem Statement You are given a Binary Tree, and you need...read more
A Software Developer Intern was asked Q. Next Greater Element Problem Statement Given a list of integers of size N, your ...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Find All Pairs Adding Up to Target Given an array of integers ARR of length N an...read more
A Software Developer Intern was asked Q2. Binary Tree Diameter Problem Statement You are given a Binary Tree, and you need...read more
A Software Developer Intern was asked Q3. Next Greater Element Problem Statement Given a list of integers of size N, your ...read more
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

