No Map, No ExtraSpace , 0ms  - " SIMPLE RECURSION " (c++)
Firstly, There are Two approaches to this question.\n\n1 -> Out of these two approaches the first one is using Map Function and other data structure which is in
Firstly, There are Two approaches to this question.\n\n1 -> Out of these two approaches the first one is using Map Function and other data structure which is in-efficient and in addition to this, this approach is rejected by many company.\n\nTHE NAIVE/IN-EFFICIENT APPROACH ( REJECTED BY MANY COMPANYS )\n\n///\n\nclass Solution {\npublic:\n\n\n    void MarkParentOfEachNode(TreeNode* root,unordered_map<TreeNode*,TreeNode*> &parent)\n    {\n        queue<TreeNode*> q;       \n        q.push(root);\n        \n        while(!q.empty())\n        {\n            int n = q.size();\n            for(int i = 0 ; i< n ; i++)\n            {\n                TreeNode* p = q.front();\n                q.pop();\n                \n                if(p->left)\n                {\n                    parent[p->left] = p;\n                    q.push(p->left);\n                }\n                if(p->right)\n                {\n                    parent[p->right] = p;\n                    q.push(p->right);\n                }\n            }\n        }\n    }\n    \n    vector<int> distanceK(TreeNode* root, TreeNode* target, int k) {\n        unordered_map<TreeNode*,TreeNode*> parent;\n        MarkParentOfEachNode(root,parent);\n        \n        unordered_map<TreeNode*,bool> visited;\n        \n        queue<TreeNode*> q;\n        q.push(target);\n        visited[target] = true;\n        \n        int distance = 0;\n        \n        while(!q.empty())\n        {\n            int n = q.size();\n            \n            if(distance++ == k)\n                break;\n            \n            for(int i = 0 ; i < n ; i++)\n            {\n                auto p = q.front();\n                q.pop();\n                \n                if(p->left && !visited[p->left])\n                {\n                    q.push(p->left);\n                    visited[p->left] = true;\n                }\n                \n                if(p->right && !visited[p->right])\n                {\n                    q.push(p->right);\n                    visited[p->right] = true;\n                }\n                \n                if(parent[p] && !visited[parent[p]])\n                {\n                    q.push(parent[p]);\n                    visited[parent[p]] = true;\n                }\n            }\n        }\n        \n        vector<int> finalans;\n        while(!q.empty())\n        {\n            TreeNode* it = q.front();\n            q.pop();\n            finalans.push_back(it->val);\n        }\n        \n        return finalans;\n    }\n};\n\n\n///\n\n2-> THE EFFICIENT APPROACH TO THIS PROBLEM IS SIMPLE RECURSION.\n\nHere we have performed simple recursion and the concept we have used is of  NODE TO PATH,\nAt first we have find out the path and distance covered to find it :\nif we dont find the value then we return -1 ( NO PATH IS COVERED )\nif we find the value then we find out the distance covered.\nThen we find out the node for the remaining distance .\n\nTO GET IT MORE CLEAR ( WATCH PEPCODING SOlUTION(The optimized one - level 2 ))\n\n///\n\n\nclass Solution {\npublic:\n\n    void Kdown(TreeNode* root,int k,TreeNode* BlockNode, vector<int>&ans)  //To find node at particular distance \n    {\n        // k is the distance \n        if(!root || k < 0 || root == BlockNode)\n            return;\n\t\t\t\n        if(k == 0)\n        {\n            ans.push_back(root->val);\n            return;\n        }\n     \n        Kdown(root->left,k-1,BlockNode,ans);\n        Kdown(root->right,k-1,BlockNode,ans); \n\t\t// we have used block node so that we dont revisit it again and avoid the cycle \n    }\n    \n    int DistanceCovered(TreeNode* root, int target ,int k , vector<int> &ans)\n    {\n        if(!root)\n            return -1; // val not found \n        \n        if(root->val == target)\n        {\n            Kdown(root,k,NULL,ans);  // we get the path at distance k\n            return 1;\n        }\n        \n        int leftDis = DistanceCovered(root->left,target,k,ans);\n        if(leftDis != -1) // value is present at left side\n        {\n            Kdown(root,k - leftDis , root->left,ans); // subtract the left side distance before calling \n            return leftDis + 1; // return the distance covered by left side \n        }\n        \n        int rightDis = DistanceCovered(root->right,target,k,ans);\n        if(rightDis != -1) // value is present at right side\n        {\n            Kdown(root,k-rightDis,root->right,ans); // same like left side\n            return rightDis + 1; // same like left side\n        }\n        \n        return -1; // didnt find the value at all\n    }\n    \n    vector<int> distanceK(TreeNode* root, TreeNode* target, int k) {\n        vector<int> ans;\n        DistanceCovered(root,target->val,k,ans);\n        return ans;\n    }\n};\n\nTimeComplexity - O(N)\nSpaceComplexity - O(1) // Tho we have used recursion stack for storing but that will be not considered \n\nUP-VOTE IF YOU FIND IT USEFULL
['Backtracking', 'Recursion', 'C']