JS || Solution by Bharadwaj
Code\n\nvar countOfPairs = function (n, x, y) {\n    let originalX = x, originalY = y;\n    x = Math.min(originalX, originalY);\n    y = Math.max(originalX, ori
# Code\n```\nvar countOfPairs = function (n, x, y) {\n    let originalX = x, originalY = y;\n    x = Math.min(originalX, originalY);\n    y = Math.max(originalX, originalY);\n    let loopSize = y - x + 1;\n    let sum = Array(n + 1).fill(0); \n    if (y - x <= 1) {\n        for (let node = 1; node < n; node++) {\n            sum[1] += 2;\n            sum[n - node + 1] -= 2;\n        }\n    } else {\n        for (let left = 1; left < x; left++) {\n            let remainingNodesLeft = x - left - 1;\n            sum[1] += 2;\n            sum[remainingNodesLeft + 1] -= 2;\n        }\n        for (let right = y + 1; right < n; right++) {\n            let remainingNodesRight = n - right;\n            sum[1] += 2;\n            sum[remainingNodesRight + 1] -= 2;\n        }\n        let rightNodes = n - y;\n        for (let left = 1; left < x; left++) {\n            let extraDist = Math.max(0, x - left - 1);\n            let startDist = 3 + extraDist;\n            sum[startDist] += 2;\n            sum[startDist + rightNodes] -= 2;\n        }\n        for (let node = x; node <= y; node++) {\n            if (loopSize % 2 === 1) {\n                sum[1] += 2;\n                sum[Math.floor(loopSize / 2) + 1] -= 2;\n            } else {\n                sum[1] += 2;\n                sum[loopSize / 2]--;\n                sum[(loopSize / 2) + 1]--;\n            }\n        }\n\n        let leftNodes = x - 1;\n        for (let node = x; node <= y; node++) {\n            let distToLeft = 1 + Math.min(node - x, y - node + 1);\n            sum[distToLeft] += 2;\n            sum[distToLeft + leftNodes] -= 2;\n\n            let distToRight = 1 + Math.min(y - node, node - x + 1);\n            sum[distToRight] += 2;\n            sum[distToRight + rightNodes] -= 2;\n        }\n    }\n\n    for (let i = 1; i <= n; i++) {\n        sum[i] += sum[i - 1];\n    }\n    sum.shift();\n    while (sum.length > n) sum.pop();\n    return sum;\n};\n```
['JavaScript']