Diameter of Binary Tree
The diameter is the length (in edges) of the longest path between any two nodes, and that path may or may not pass through the root. The trick: compute height recursively as usual, but at every node, check whether leftHeight + rightHeight beats the best diameter seen so far (the path "through" that node).
diameterOfBinaryTree(tree([1, 2, 3, 4, 5])); // 3 (path 4 -> 2 -> 1 -> 3)