As reported: eBay Software Engineer, DSA round 1 (2026): diameter of a binary tree.
Given the root of a binary tree, return the length of its diameter: the number of edges on the longest path between any two nodes. The path may or may not pass through the root.
This is LeetCode 543 — Diameter of Binary Tree.
Example 1
root = [1,2,3,4,5] -> 3 (path 4 -> 2 -> 1 -> 3, or 5 -> 2 -> 1 -> 3)
Example 2
root = [1,2] -> 1
Constraints: 1 ≤ number of nodes ≤ 10^4; -100 ≤ Node.val ≤ 100.
Code runner format: one line, the tree in LeetCode's level-order format. Implement diameterOfBinaryTree(root); the harness prints the length.