JAVA BFS solution
Code\njava []\nclass Solution {\n    \n    public int[] countOfPairs(int n, int x, int y) {\n        // Initialize an array to store the count of pairs for each
# Code\n```java []\nclass Solution {\n    \n    public int[] countOfPairs(int n, int x, int y) {\n        // Initialize an array to store the count of pairs for each distance\n        int[] res = new int[n];\n\n        // Create an adjacency list for the houses and streets\n        Map<Integer, List<Integer>> adjacencyList = new HashMap<>();\n        for (int i = 1; i <= n; i++) {\n            adjacencyList.put(i, new ArrayList<>());\n        }\n\n        for (int i = 1; i < n; i++) {\n            adjacencyList.get(i).add(i + 1);\n            adjacencyList.get(i + 1).add(i);\n        }\n\n        // Add the additional street connecting house x and house y\n        adjacencyList.get(x).add(y);\n        adjacencyList.get(y).add(x);\n\n        // Define a BFS function to find the minimum distance from a house\n        for (int i = 1; i <= n; i++) {\n            bfs(i, adjacencyList, res);\n        }\n\n        return res;\n    }\n\n    private void bfs(int i, Map<Integer, List<Integer>> adjacencyList, int[] res) {\n        Queue<int[]> queue = new LinkedList<>();\n        Set<Integer> visited = new HashSet<>();\n        queue.offer(new int[]{i, 0});\n        visited.add(i);\n\n        while (!queue.isEmpty()) {\n            int[] current = queue.poll();\n            int node = current[0];\n            int dist = current[1];\n\n            // Count the pairs if distance > 0\n            if (dist > 0) {\n                res[dist - 1]++;\n            }\n\n            for (int neighbor : adjacencyList.get(node)) {\n                if (!visited.contains(neighbor)) {\n                    visited.add(neighbor);\n                    queue.offer(new int[]{neighbor, dist + 1});\n                }\n            }\n        }\n    }\n}\n```
['Breadth-First Search', 'Java']