Simple Python Solution. Well explained 🔥
Intuition and ApproachFor a pair of node, there are three options to reach house2 from house1:
go directly from house1 to house2, the distance is abs(house2 - h
# Intuition and Approach
For a pair of node, there are three options to reach house2 from house1:
1. go directly from house1 to house2, the distance is `abs(house2 - house1)`
2. go from house1 to x, then to y and reach housr2 finally, the total distance is the `distance(house1, x) + distance(x, y) + distance(house2, y)`
3. like option 2, we go to y first, the total distance is `distance(house1, y) + distance(y, x) + distance(house2, x)`

Compare the above three options and find the min distance


# Complexity
- Time complexity:
O(n ** 2)

- Space complexity:
O(1)

# Code
```python3 []
class Solution:
    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:
        result = [0] * n

        for house1 in range(n):
            for house2 in range(house1 + 1, n):
                direct_distance = house2 - house1
                # Since the given house location is 1 index based, we need to convert to 0 index based
                detour_distance_x_to_y = abs(house1 - x + 1) + 1 + abs(house2 - y + 1)
                detour_distance_y_to_x = abs(house1 - y + 1) + 1 + abs(house2 - x + 1)

                min_distance = min([direct_distance, detour_distance_x_to_y, detour_distance_y_to_x])

                result[min_distance - 1] += 2
        
        return result

```
['Python3']