Python - HashMap / Breadth First Search, Time O(n), Space O(n)
python\nclass Solution:\n    def distanceK(self, root: TreeNode, target: TreeNode, K: int) -> List[int]:\n        self.parent = {}\n        self.getParents(root
```python\nclass Solution:\n    def distanceK(self, root: TreeNode, target: TreeNode, K: int) -> List[int]:\n        self.parent = {}\n        self.getParents(root, None)\n        return self.bfs(target, K)\n    \n    def getParents(self, node: TreeNode, parent: TreeNode) -> None: \n        if node == None: return\n        \n        self.parent[node] = parent\n        \n        self.getParents(node.left, node)\n        self.getParents(node.right, node)\n        \n    def bfs(self, start: TreeNode, K: int) -> List[int]:\n        res, q, visited = [], deque([(start, 0)]), set()\n        \n        while q:\n            n, d = q.popleft()\n            \n            if n not in visited:\n                if d == K: \n                    res.append(n.val)\n                    continue\n                    \n                visited.add(n)\n                \n                if n.left: q.append((n.left, d+1))\n                if n.right: q.append((n.right, d+1))\n                if self.parent[n]: q.append((self.parent[n], d+1))\n                                   \n        return res\n```
['Breadth-First Search', 'Python']