Easy to understand | Faster than 93% | O(n) space
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nFaster than 93% solutions.\n\n\n\n# Complexity\n- Time complexity:\nO(n^2
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nFaster than 93% solutions.\n![image.png](https://assets.leetcode.com/users/images/de80c7bc-82ef-463d-8abb-bb1333adc067_1724218931.5486207.png)\n\n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(n)\n\n# Code\n```python3 []\nfrom typing import List\n\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        res = [0] * (n + 1)\n\n        if x > y:\n            x, y = y, x\n        \n        for i in range(1, n + 1):\n            for j in range(i + 1, n + 1):\n                direct_dist = j - i\n                via_x_y = abs(x - i) + 1 + abs(y - j)\n                min_dist = min(direct_dist, via_x_y)\n                res[min_dist] += 2\n\n        return res[1:]\n\n```
['Python', 'Python3']