All Nodes Distance K In Binary Tree

medium
1. Given the root of a binary tree.
2. The value of a target node target, and an integer k.
3. You have return an array of the values of all nodes that have a distance k from the target node.

Input Format

Input is managed for you.

Output Format

Output is managed for you.

Constraints

1. The number of nodes in the tree is in the range [1, 10000].
2. -1000 <= Node.val <= 1000
3. All the values Node.val are unique.
4. target is the value of one of the nodes in the tree.
5. 0 <= k <= 1000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
15
4
2
1
-1
-1
3
-1
-1
6
5
-1
-1
7
-1
-1
2 2
Output
6 
Previous
Serialize And Deserialize N - Ary Tree
Next
Construct Binary Tree From Inorder And Levelorder Traversal

Related Questions