JavaScript O(n*n*n)
Intuition\nFloyd Algorithm.\n# Approach\nFloyd Algorithm.\n# Complexity\n- Time complexity:\nO(nnn)\n- Space complexity:\nO(n*n)\n# Code\n\n/**\n * @param {numb
# Intuition\nFloyd Algorithm.\n# Approach\nFloyd Algorithm.\n# Complexity\n- Time complexity:\nO(n*n*n)\n- Space complexity:\nO(n*n)\n# Code\n```\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 matrix = new Array(n)\n    for (const i of matrix.keys()) {\n        const row = new Array(n)\n        for (const j of row.keys()) {\n            let outcome = Infinity\n            if (j === i)\n                outcome = 0\n            else if (j === i + 1 || j === i - 1)\n                outcome = 1\n            row[j] = outcome\n        }\n\n        matrix[i] = row\n    }\n    matrix[x - 1][y - 1] = matrix[y - 1][x - 1] = 1\n\n    // pivot must come first\n    for (let k = 0; k < n; k++) {\n        for (let i = 0; i < n; i++) {\n            for (let j = 0; j < n; j++) {\n                const indirect = matrix[i][k] + matrix[k][j]\n                if (indirect < matrix[i][j])\n                    matrix[i][j] = matrix[j][i] = indirect\n            }\n        }\n    }\n\n\n    const result = new Array(n).fill(0)\n    for (let i = 0; i < n; i++) {\n        for (let j = 1 + i; j < n; j++) {\n            const distance = matrix[i][j]\n            const key = distance - 1\n            result[key] += 2\n        }\n    }\n\n\n    return result\n};\n```
['JavaScript']