Count Special Point Triplets
You are given a list of distinct points on a 2D plane, where points[i] = [xi, yi].
A special triplet is an ordered tuple of points (i, j, k) such that:
- the distance between point i and point j is equal to the distance between point i and point k
- j and k are different points
- the order matters, so (i, j, k) and (i, k, j) are counted separately
Return the total number of such special triplets.
Note: You only need to compare distances. Using squared distance is enough: (x2 - x1)2 + (y2 - y1)2
Example 1:
Input: points = [[0,0],[1,0],[0,1]]
Output: 2
Explanation:
Take point [0,0] as the center.
- Distance from [0,0] to [1,0] = 1
- Distance from [0,0] to [0,1] = 1
So we can form these two ordered triplets:
- ([0,0], [1,0], [0,1])
- ([0,0], [0,1], [1,0])
Hence, the answer is 2.
Example 2:
Input: points = [[0,0],[1,0],[-1,0],[0,2]]
Output: 4
Now Your Turn!
Pick the correct output for the given inputInput: points = [[0,0],[1,0],[-1,0],[0,1],[0,-1]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= points.length <= 500
- points[i].length == 2
- -104 <= xi, yi <= 104
- All points are distinct