Tap here to switch tabs
Problem
Submissions

Problem: All Nodes Distance K in Binary Tree

Try to solve the All Nodes Distance K in Binary Tree problem.

Statement

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

The answer may be returned in any order.

Constraints:

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

  • 0≤0 \leq Node.val ≤500\leq 500

  • All the values Node.val are unique.

  • target is the value of one of the nodes in the tree.

  • 0≤0 \leq k ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: All Nodes Distance K in Binary Tree

Try to solve the All Nodes Distance K in Binary Tree problem.

Statement

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

The answer may be returned in any order.

Constraints:

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

  • 0≤0 \leq Node.val ≤500\leq 500

  • All the values Node.val are unique.

  • target is the value of one of the nodes in the tree.

  • 0≤0 \leq k ≤1000\leq 1000