All the Nodes at a distance of K in a Binary Tree
CodeChefOpen on judge ↗
You are given the **root** of a binary tree, a **target node** (`TreeNode* target`), and an integer **k**. Your task is to **return all node values that are exactly $k$ edges away** from the target node. The nodes can be in any direction — **upward or downward** — and the answer can be returned **in any order**. ### Function Declaration - **Function Name** - $distanceK$ - **Parameters**
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start