Longest Path in a Tree
Asked at Meta · Coding Questions · Difficulty: Medium · Last asked Apr 2, 2026
You are given an undirected tree with `n` nodes labelled `0` to `n - 1`, as a list of `n - 1` edges. The distance between two nodes is the number of edges on the path between them. Find the largest distance between any two nodes of the tree (its diameter).
Loading the problem…
More Meta interview questions
- LLM conceptual questions
- Implement a Two-Hidden-Layer MLP with Backpropagation in NumPy
- Dot Product with Run-Length Encoded Vectors
- Count Lakes Wrapped by a Given Island
- Minimum Remove to Make Valid Parentheses
- LLM with Beam Search and Nucleus Sampling (Meta MSL)