Easy c++ solution with explanation and comments
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nWe will calculate bfs o
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe will calculate bfs of each node. For each node, whatever will be the size of each level, add it to that index of the answer array. \n\n\n# Complexity\n- Time complexity:O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void bfs(int src, unordered_map<int, list<int>>& adjList, vector<int>& ans){\n        unordered_map<int, bool>visited;\n        queue<int>q;\n        visited[src] = 1;\n        q.push(src);\n        \n        int level = 0;\n        while(!q.empty()){\n            int n = q.size();\n            while(n--){\n                int front = q.front();\n                q.pop();\n                for(auto& neighbour: adjList[front]){\n                    if(!visited[neighbour]){\n                        q.push(neighbour);\n                        visited[neighbour] = 1;\n                    }\n                }\n            }\n            //updating each level of the answer with the size of that queue level\n            ans[level] += (q.size());\n            level++;\n        }\n\n    }\n    vector<int> countOfPairs(int n, int x, int y) {\n        unordered_map<int, list<int>>adjList;\n        //calculating adjacency list\n        for(int i=1; i< n; i++){\n            adjList[i].push_back(i+1);\n            adjList[i + 1].push_back(i);\n        }\n\n        //checking if the x and y are not same. If same, the path is from self node to self. \n        if(x != y){\n            adjList[x].push_back(y);\n            adjList[y].push_back(x);\n        }\n        vector<int>ans(n,0);\n\n        //calculating bfs with each node as source\n        for(int i = 1; i<= n; i++){\n            \n            bfs(i, adjList, ans);\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'C++']