All Nodes Distance K in Binary Tree

Medium · Trees · about 25 minutes

Asked at Meta, Amazon, Microsoft, Google, LinkedIn, Apple.

All node values in the tree are distinct. Starting at the node whose value is target, find every node that is exactly k edges away (moving up to parents as well as down to children) and return their values in any order.

Related guides