Search
⌘K

Leetcode 1522. Diameter of N-Ary Tree

Compute the diameter (longest path in edges between any two nodes) of an N-ary tree by using a post-order traversal to obtain subtree heights and combining the two largest child heights at each node to update a global maximum; this is a tree/DFS problem solvable in O(n) time and O(h) recursion space.

Asked at:

Google

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid December, 2024

Google

Google

Mid-level

Solve a problem related to n-ary trees using DFS and backtracking

Comments

Your account is free and you can post anonymously if you choose.