Easy and Understandable Java Solution
\nclass Solution {\n  \n    public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {\n        List<Integer> ans = new ArrayList<>();\n        \n 
```\nclass Solution {\n  \n    public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {\n        List<Integer> ans = new ArrayList<>();\n        \n        HashMap<TreeNode, Integer> hm = new HashMap<>();\n        Queue<TreeNode> q = new LinkedList<>();\n        q.add(root);\n        int level=0;\n        //Storing the Levels in Map for each node via BFS\n        while(!q.isEmpty()){\n            int size = q.size();\n            level++;\n            while(size-->0){\n                TreeNode curr = q.poll();\n                hm.put(curr, level);\n                if(curr.left!=null){\n                    q.add(curr.left);\n                }\n                if(curr.right!=null){\n                    q.add(curr.right);\n                }\n                \n            }\n        }\n        \n        //For every node in Tree (every key in Map)\n        //calculating the distance between target and node.\n        \n        //                                  3         -------level 1\n        //                              /       \\\n        //                             5         1     -------level 2\n        //                           /   \\     /   \\\n        //                          6     2   0     8  -------level 3\n        //                              /   \\\n        //                             7     4         ------level 4\n                                     \n        //say the current node, which we are at while iterating all nodes is 1.\n        //target node is 5\n        //lowest common anscestor of 5 and 1 is 3.\n        //a = distance between lcs and target\n        //a is calculated subtracting the levels of lcs and target\n        //eg. lcs 3 is at level 1, and target 5 is at level 2 => a = 2-1 = 1\n        //b = distance between lcs and current node       \n        //b is calculated subtracting the levels of lcs and current Node\n        //eg. lcs 3 is at level 1, and current node 1 is at level 2 => b = 2-1 = 1\n        //now the distance beetween target 5 and current node 1 will be a+b, ie. 1+1=2\n        //is a+b==k (2==2), add in the result list.\n        for(Map.Entry<TreeNode, Integer> entry: hm.entrySet()){\n            TreeNode lcs = lcs(root, target, entry.getKey());\n            if((hm.get(entry.getKey())-hm.get(lcs)) + (hm.get(target)-hm.get(lcs)) == k){\n                ans.add(entry.getKey().val);\n            }\n        }\n        \n        return ans;\n    }\n    \n    //Calculating Lowest Common Ancestor\n    TreeNode lcs(TreeNode root, TreeNode p, TreeNode q){\n        if(root==null || p==root || q==root){\n            return root;\n        }\n        TreeNode left = lcs(root.left, p, q);\n        TreeNode right = lcs(root.right, p, q);\n        if(left!=null && right!=null){\n            return root;\n        }\n        return left!=null?left:right;\n        \n    }\n    \n}\n```\n\nPlease upvote if helpful
['Breadth-First Search', 'Java']