Simple bfs solution
Intuition\n Describe your first thoughts on how to solve this problem. \n    The goal is to determine the minimum number of streets needed to travel\n    from o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n    The goal is to determine the minimum number of streets needed to travel\n    from one house (house1) to another (house2). To achieve this, the BFS\n    algorithm is employed to find the shortest distance between houses.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n    The chosen approach involves using a Breadth-First Search (BFS) for\n    each house individually. For every house, a BFS traversal is initiated\n    to determine the minimum distance to all other houses, and these\n    distances are aggregated to obtain the final result. \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n        O(n^2) - Since a BFS traversal is performed for each house in the\n                 range of 1 to n, resulting in a quadratic time complexity.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n        O(n^2) - For each house, a queue and an additional set are\n                 utilized in the BFS process, contributing to O(n) space\n                 for each BFS call.\n# Code\n```\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        # Initialize a list to store the count of pairs for each distance\n        res = [0] * n\n        \n        # Create an adjacency list for the houses and streets\n        adjacency_list = defaultdict(list)\n        for i in range(1, n):\n            adjacency_list[i].append(i + 1)\n            adjacency_list[i + 1].append(i)\n        \n        # Add the additional street connecting house x and house y\n        adjacency_list[x].append(y)\n        adjacency_list[y].append(x)\n        \n        # Define a BFS function to find the minimum distance from a house\n        def bfs(i):\n            q = deque()\n            visit = set()\n            q.append((i, 0))\n            visit.add(i)\n\n            while q:\n                i, dist = q.popleft()\n                if dist > 0:\n                    res[dist - 1] += 1\n                for nei in adjacency_list[i]:\n                    if nei not in visit:\n                        visit.add(nei)\n                        q.append((nei, dist + 1))\n\n        # Iterate through each house and perform BFS\n        for i in range(1, n + 1):\n            bfs(i)\n        \n        return res\n        \n```
['Breadth-First Search', 'Graph', 'Python3']