Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Diameter of N-Ary Tree



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Diameter of Multi-Child Tree

Diameter of Multi-Child Tree

Problem Statement

Given the rootNode of a multi-child tree, your task is to find the length of the longest path between any two nodes in the tree.

This longest path is referred to as the diameter of the tree, and it does not necessarily have to pass through the root node.

(The tree is represented in level order format where each group of children is separated by a null value.)

Examples

Example 1:

Input: rootNode = [1,null,4,2,5,null,7,8]
Output: 3
Explanation: The diameter path length is 3.

Example 2:

Input: rootNode = [1,null,3,null,4,5,null,6,null,7]
Output: 4

Example 3:

Input: rootNode = [1,null,2,4,6,7,null,null,8,9,null,10,null,11,null,null,12,null,13,null,null,14]
Output: 7

Constraints

  • The tree depth will not exceed 900.
  • Number of nodes will be in the range [0, 9000].