JS/TS Solution Brute Force
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\n\nfor (let i = 1; i <= n; i++) {\n    for (let j = i + 1; j <= n; j++) 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n```\nfor (let i = 1; i <= n; i++) {\n    for (let j = i + 1; j <= n; j++) {\n        // Compute distance between house i and house j\n        const distance = Math.min(\n            Math.abs(i - j),\n            Math.abs(i - x) + Math.abs(j - y) + 1,\n            Math.abs(i - y) + Math.abs(j - x) + 1\n        );\n        result[distance - 1]++;\n    }\n}\n\n```\nOuter Loop (i): Iterates from house 1 to house n.\n\nInner Loop (j): For each i, iterates from i + 1 to house n. This ensures that each pair (i, j) is unique and avoids duplicate counting (since (i, j) is the same as (j, i)).\n\nCalculating Distance:\n\nDirect Path: Math.abs(i - j) computes the absolute difference between i and j, representing the number of streets between them via the linear connections.\nPath via Shortcut (x to y):\n\nFirst Shortcut Path: Math.abs(i - x) + Math.abs(j - y) + 1\nMath.abs(i - x): Distance from house i to house x via the linear streets.\n\nMath.abs(j - y): Distance from house j to house y via the linear streets.\n\n 1: The additional shortcut street connecting x and y.\nSecond Shortcut Path: Math.abs(i - y) + Math.abs(j - x) + 1\nSimilar to the first path but swapping x and y, accounting for the possibility that taking the shortcut from y to x might be shorter.\nMinimum Distance: Math.min(...) selects the smallest distance among the three calculated paths, ensuring that we always consider the shortest possible path between i and j.\n<!-- Describe your approach to solving the problem. -->\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```javascript []\n/**\n * @param {number} n\n * @param {number} x\n * @param {number} y\n * @return {number[]}\n */\nvar countOfPairs = function (n, x, y) {\n    const result = new Array(n).fill(0);\n\n    for (let i = 1; i <= n; i++) {\n        for (let j = i + 1; j <= n; j++) {\n            const distance = Math.min(\n                Math.abs(i - j),\n                Math.abs(i - x) + Math.abs(j - y) + 1,\n                Math.abs(i - y) + Math.abs(j - x) + 1\n            );\n            result[distance - 1]++;\n        }\n    }\n\n    return result.map((count, index) => count * 2);\n};\n```
['Graph', 'TypeScript', 'JavaScript']