Python - Convert to Graph and run BFS (Detailed explanation)
Intuition: We want to do a BFS and return all the values K distance from target.\nWe hit a minor obstacle because we cannot traverse a tree backwards.\n\nSo we 
***Intuition***: We want to do a BFS and return all the values K distance from target.\nWe hit a minor obstacle because we cannot traverse a tree backwards.\n\nSo we ask ourselves, what do we know about a tree?\nTree is a directed acyclic graph. If we could convert the tree to a undirected graph (or bidrected in the code below) we could simply run a BFS on the adjacency list of each node... voila !\n\nLet\'s begin.\n\n```\nclass Solution:\n    def convert_into_graph(self, node, parent, g):\n        # To convert into graph we need to know who is the parent\n        if not node:\n            return\n        \n        if parent:\n            g[node].append(parent)\n            \n        if node.right:\n            g[node].append(node.right)\n            self.convert_into_graph(node.right, node, g)\n        \n        if node.left:\n            g[node].append(node.left)\n            self.convert_into_graph(node.left, node, g)\n        \n    def distanceK(self, root: TreeNode, target: TreeNode, K: int) -> List[int]:\n        g = defaultdict(list)\n        vis, q, res = set(), deque(), []\n        # We have a graph, now we can use simply BFS to calculate K distance from node.\n        self.convert_into_graph(root, None, g)\n        \n        q.append((target, 0))\n        \n        while q:\n            n, d = q.popleft()\n            vis.add(n)\n            \n            if d == K:\n                res.append(n.val)\n            \n            # adjacency list traversal\n            for nei in g[n]:\n                if nei not in vis:\n                    q.append((nei, d + 1)) \n                \n        return res\n```
['Breadth-First Search', 'Graph', 'Python']