Java Solution || BFS || O(N^2)
\n\n# Code\njava []\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n\n        List<List<Integer>> list = new ArrayList<>();\n\n        
\n\n# Code\n```java []\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n\n        List<List<Integer>> list = new ArrayList<>();\n\n        for(int i=0;i<=n;i++){\n            list.add(new ArrayList<>());\n        }\n\n        for(int i=1;i<n;i++){\n            list.get(i).add(i+1);\n            list.get(i+1).add(i);\n        }\n\n        list.get(x).add(y);\n        list.get(y).add(x);\n\n        int[] answer = new int[n];\n\n        for(int i=1;i<=n;i++){\n            dfs(list, answer, i);\n        }\n\n        return answer;\n        \n    }\n\n    public void dfs(List<List<Integer>> list, int[] answer, int source){\n        Queue<int[]> que = new LinkedList<>();\n        que.add(new int[]{source, 0});\n        \n        int[] dist = new int[list.size()]; //n+1 size means n idex accesible\n        Arrays.fill(dist, Integer.MAX_VALUE);\n        dist[source] = 0;\n\n        while(!que.isEmpty()){\n            int[] pair = que.remove();\n            int node = pair[0];\n            int wei = pair[1];\n\n            if(dist[node]<wei){\n                continue;\n            }\n\n            if(wei>0){\n                answer[wei-1]++;\n            }\n\n            for(int nei: list.get(node)){\n                if(wei+1<dist[nei]){\n                    dist[nei] = wei+1;\n                    que.add(new int[]{nei, wei+1});\n                }\n            }\n        }\n    }\n}\n```
['Java']