Not So Long | Very Short & Easy with Explanation | C++ Code
Steps\nRead one line and check code for reference then continue.\n1. Find the path of the target node and store it in an array. \n2. The last element (n-1) elem
# Steps\n**Read one line and check code for reference then continue.**\n1. Find the path of the target node and store it in an array. \n2. The last element (n-1) element has the target node. Find nodes that are k distance below it. \n3. Take v=1.\n4. Run a loop from last second element to above (k-1) path parents. \n5. For each path parent find (k-v) distance nodes. Rember to not consider the child node which was already processed. \n6. Store answer each time while calling find function.\n7. Return ans.\n```\nclass Solution\n{\n    public:\n        void getPath(TreeNode *root, vector<TreeNode*> &path, vector<TreeNode*> current, TreeNode *target)\n        {\n            if (!root) return;\n\n            if (root == target)\n            {\n                current.push_back(root);\n                path = current;\n                return;\n            }\n\n            current.push_back(root);\n            getPath(root->left, path, current, target);\n            getPath(root->right, path, current, target);\n            current.pop_back();\n        }\n    void find(TreeNode *root, TreeNode *never, int level, int k, vector<int> &ans)\n    {\n        if (!root or root == never) return;\n\n        if (level == k)\n        {\n            ans.push_back(root->val);\n            return;\n        }\n\n        find(root->left, never, level + 1, k, ans);\n        find(root->right, never, level + 1, k, ans);\n    }\n    vector<int> distanceK(TreeNode *root, TreeNode *target, int k)\n    {\n        vector<int> ans;\n        vector<TreeNode*> path, current;\n        getPath(root, path, current, target); //(step 1)\n\n        int n = path.size();\n        int start = n - k, v = 1; //(step 3)\n\t\n\t\t//(nullptr because no element below the target node is processed)\n        find(path[n - 1], nullptr, 0, k, ans); //(step 2)\n        \n        for (int i = n - 2; i >= 0 and n >= start; i--) //(step 4)\n        {\n\t\t\t//(step 5 & 6, exclude path[i+1] which is already processed)\n            find(path[i], path[i + 1], 0, k - v, ans); \n            v++;\n        }\n        return ans; //(step 7)\n    }\n};\n```\n```\n  \n  _____  _                       _    _                 _       \n |  __ \\| |                     | |  | |               | |      \n | |__) | | ___  __ _ ___  ___  | |  | |_ ____   _____ | |_ ___ \n |  ___/| |/ _ \\/ _` / __|/ _ \\ | |  | | \'_ \\ \\ / / _ \\| __/ _ \\\n | |    | |  __/ (_| \\__ \\  __/ | |__| | |_) \\ V / (_) | ||  __/\n |_|    |_|\\___|\\__,_|___/\\___|  \\____/| .__/ \\_/ \\___/ \\__\\___|\n                                       | |                      \n                                       |_|                      \n\n```
['Binary Tree']