Simple solution🎯|| BFS
Intuition\nmaking a 2D vector(suppose dis) that contains all the distances from a house to all the other houses. \nthan suppose the vector we want to return is 
# Intuition\nmaking a 2D vector(suppose dis) that contains all the distances from a house to all the other houses. \nthan suppose the vector we want to return is ans \nans[i] will the the number of times i appears in dis\n\n\n# Approach\njust like dijiktra algorithm do BFS to find dis \n\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    void BFS(vector<vector<int>>a,int i,vector<int> &dis,int n){\n        queue<int>q;\n        q.push(i);\n        dis[i]=0;\n        while(!q.empty()){\n            int f=q.front();\n            q.pop();\n            \n            for(int j:a[f]){\n                if(dis[j]==-1){\n                    dis[j]=dis[f]+1;\n                    q.push(j);\n                }\n            }\n        }\n    }\n    \n    vector<int> countOfPairs(int n, int x, int y) {\n        vector<vector<int>>a(n+1);\n        for(int i=1;i<n;i++){\n            a[i].push_back(i+1);\n            a[i+1].push_back(i);\n        }\n        a[x].push_back(y);\n        a[y].push_back(x);\n        \n        vector<vector<int>>dis(n+1,vector<int>(n+1,-1));\n        for(int i=1;i<=n;i++){\n            BFS(a,i,dis[i],n);\n        }\n\n        vector<int>ans(n);\n        \n        for(int i=1;i<dis.size();i++){\n            for(int j=1;j<dis[i].size();j++){\n                if(i!=j){\n                    ans[dis[i][j]-1]++;\n                }\n            }\n        }\n        \n        //uncomment to print dis vector \n\n        //for(int i=0;i<dis.size();i++){\n        //    for(int j=0;j<dis[i].size();j++){\n        //        if(i==0){\n        //            cout<<j<<" ";\n        //        }\n        //        else if(j==0){\n        //            cout<<"#"<<" ";\n        //        }\n        //        else if(j==i){\n        //            cout<<"#"<<" ";\n        //        }\n        //        else{cout<<dis[i][j]<<" ";}\n        //    }\n        //    cout<<endl;\n        //}\n        \n        return ans;\n    }\n};\n```
['C++']