Simplest Logic || Clear || Easy
Intuition\n Describe your first thoughts on how to solve this problem. \n\n # Approach \n Describe your approach to solving the problem. \n\n # Complexity \n - 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n\n<!-- # Complexity -->\n<!-- - Time complexity: -->\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n<!-- - Space complexity: -->\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] countOfPairs(int n, int x, int y) {\n        \n        Map<Integer,List<Integer>> mp=new HashMap();\n        for(int i=1;i<=n;++i) mp.put(i,new ArrayList());\n        int[] ans=new int[n];\n\n        for(int i=1;i<n;++i){\n            mp.get(i).add(i+1);\n            mp.get(i+1).add(i);\n        }\n\n        mp.get(x).add(y);\n        mp.get(y).add(x);\n\n        for(int i=1;i<=n;++i){\n            Set<Integer> hs=new HashSet();\n            Queue<Integer> q=new LinkedList();\n            q.add(i);\n            int l=0;\n            while(!q.isEmpty()){\n                int s=q.size();\n                hs.add(q.peek());\n                int c=0;\n                for(int k=0;k<s;++k){\n                    int h=q.poll();\n                    for(int j:mp.get(h)){\n                        if(!hs.contains(j)){\n                            hs.add(j);\n                            q.add(j);\n                            c++;\n                        }\n                    }\n                }\n                ans[l]+=c;\n                l++;\n            }\n        }\n        return ans;\n    }\n}\n```
['Breadth-First Search', 'Java', 'Python3']