Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA

Problem: A binary tree is given by level order [1, 2, 3, 4, 5, None, 6]. Its diameter is the largest number of edges on any path between two nodes. What is the diameter?

  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 6

Correct answer: A. 4

At each node, the best path through it joins the heights of its two subtrees. Taking the height of the tree alone gives the depth, not the longest path.

More Coding Interview Problems questions

Exams that ask this topic