Search⌘ K
AI Features

Solution: All Nodes Distance K in Binary Tree

Let's solve the All Nodes Distance K in Binary Tree problem using the Graphs pattern.

Statement

Given the root of a binary tree, a target node target, and an integer k, return an array of values of all nodes in the tree that are exactly at distance k from target.

The result can be returned in any order.

Constraints:

  • The number of nodes in the tree is in the range [1,500][1, 500] ...