Number of Good Leaf Nodes Pairs
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given the root of a binary tree and an integer distance. A pair of two **different** leaf nodes is **good** when the number of edges on the shortest path between them is at most distance.
Return the number of good leaf pairs. Each unordered pair is counted once.
A tree consisting of a single node has one leaf and therefore no pairs.
Examples
Constraints
- 1 <= number of nodes <= 2^10
- 1 <= Node.val <= 100
- 1 <= distance <= 10
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.