Longest Path Between Nodes

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • medium
  • Pro

Given a binary tree, find its diameter: the number of edges on the longest path between any two nodes, which may or may not pass through the root. Explain how to do it in a single traversal.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →