Simple logic explained || Easy to understand || C++ || O(n^2)
We want to reach from j -> i\npath 1 : j->i , streets = (i-j)\npath 2 : j->x->y->i , streets = abs(j-x) + 1 + abs(i-y)\ntake the path which has less streets\n\n
We want to reach from j -> i\npath 1 : j->i , streets = (i-j)\npath 2 : j->x->y->i , streets = abs(j-x) + 1 + abs(i-y)\ntake the path which has less streets\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> countOfPairs(int n, int x, int y) {\n        // to make sure that x<=y in every case\n        if(x>y)\n            return countOfPairs(n, y, x);\n        \n        vector<int> res(n, 0);\n        \n        for(int i=1;i<=n;i++){\n            for(int j=1;j<i;j++){\n                int idx = i-j;          \n                idx = min(idx, abs(j-x) + 1 + abs(i-y));\n                if(idx>=1)\n                    res[idx-1]+=2;  // add 2 as we can go from j->i and i->j\n            }\n        }\n        return res;\n        \n    }\n};\n```
['C++']