✅C++ || ✅No Graph conversion || ✅Without using extra Space || ✅Easy to understand.
Approach : Percolate Distance\nIntuition\nFrom root, say the target node is at depth 3 in the left branch. It means that any nodes that are distance K - 3 in th
# **Approach : Percolate Distance**\n**Intuition**\nFrom root, say the target node is at depth 3 in the left branch. It means that any nodes that are distance K - 3 in the right branch should be added to the answer.\n# Algorithm\nTraverse every node with a depth first search dfs. We\'ll add all nodes x to the answer such that node is the node on the path from x to target that is closest to the root.\n```\nTo help us, dfs(node) will return the distance from node to the target. Then, there are 4 cases:\n\n  1.If node == target, then we should add nodes that are distance K in the subtree rooted at target.\n  2.If target is in the left branch of node, say at distance L+1, then we should look for nodes that are distance K - L - 1 in the right branch.\n  3.If target is in the right branch of node, the algorithm proceeds similarly.\n  4.If target isn\'t in either branch of node, then we stop.\n```\n\n```\nclass Solution {\npublic:\n    void kdown(TreeNode* root, int k, TreeNode* blockNode, vector<int> &ans){\n        if(root == NULL or k < 0 or root == blockNode) return;\n        if(k == 0){\n            ans.push_back(root->val);\n            return;\n        }\n        kdown(root->left,k-1,blockNode,ans);\n        kdown(root->right,k-1,blockNode,ans);\n        \n    }\n    int distanceKk(TreeNode* root,TreeNode* target,int k,vector<int>&ans){\n        if(root == NULL) return -1;\n        if(root == target){\n            kdown(root,k-0,NULL,ans);\n            return 1;\n        }\n        int ld = distanceKk(root->left,target,k,ans);\n        if(ld != -1){\n            kdown(root,k-ld,root->left,ans);\n            return ld + 1;\n        }\n        \n        int rd = distanceKk(root->right,target,k,ans);\n        if(rd != -1){\n            kdown(root,k-rd,root->right,ans);\n            return rd + 1;\n        }\n        return -1; \n    }\n    vector<int> distanceK(TreeNode* root, TreeNode* target, int k) {\n        vector<int> ans;\n        distanceKk(root,target,k,ans);\n        return ans;\n    }\n};\n```\nGuys don\'t forget to upvote me.![image](https://assets.leetcode.com/users/images/d93c2392-2f9f-449e-9faf-addc7c0ed496_1655162232.802787.png)Please...\n
['Depth-First Search', 'Recursion', 'C', 'C++']