Diameter of a Binary Tree Problem Statement
Given a binary tree, return the length of its diameter. The diameter of a binary tree is defined as the length of the longest path between any two nodes in the tree.
Example:
Input:
The tree is represented in level order by node values, using '-1' to denote null nodes. Example input tree:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
6
Explanation:
The path with the maximum length is formed by the nodes highlighted in the image of the tree, resulting in a diameter of 6 edges.
Constraints:
1 <= T <= 10
: Number of test cases.0 <= N <= 10^5
: Total number of nodes in the binary tree.1 <= data <= 10^4
: Value of a binary tree node.- Time Limit: 1 second.
Note:
The input for each test case will be a sequence of node values arranged in level-order traversal, with '-1' used for null and placeholder nodes.

AnswerBot
1y
The diameter of a binary tree is the length of the longest path between any two end nodes in the tree.
The diameter of a binary tree can be calculated by finding the maximum of the following three valu...read more
Help your peers!
Add answer anonymously...
Top SDE-2 Interview Questions Asked at Paytm
Q. Can you describe the system design for a platform like BookMyShow and the questi...read more
Q. Connect Ropes with Minimum Cost Given 'N' ropes, each having different lengths, ...read more
Q. Maximum Subarray Sum Problem Statement Given an array ARR consisting of N intege...read more
Interview Questions Asked to SDE-2 at Other Companies
Top Skill-Based Questions for Paytm SDE-2
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Java 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

