Ctrl K

Equidistant Point Triples

Medium
There are beacons on a plane, given as beacons, where beacons[i] = [x, y]; all points are distinct. Call a triple of beacons (a, b, c) equidistant if a, b and c are three different beacons and the distance from a to b equals the distance from a to c. Order matters: (a, b, c) and (a, c, b) are different triples. Return the number of equidistant triples.
Example 1
beacons=[[0, 0], [2, 0], [0, 2]] → 2

Beacons (2, 0) and (0, 2) are both at distance 2 from (0, 0). That gives the triples ((0,0), (2,0), (0,2)) and ((0,0), (0,2), (2,0)). There are no others.

Example 2
beacons=[[0, 0], [1, 0], [-1, 0], [0, 1]] → 8

Around (0, 0) three beacons are at distance 1, giving 3·2 = 6 ordered triples. Around (0, 1) the beacons (1, 0) and (-1, 0) are both √2 away, giving 2 more. 8 in total.

Example 3
beacons=[[5, 5]] → 0

A single beacon forms no triples.

Constraints
  • 1 ≤ len(beacons) ≤ 500
  • beacons[i].length == 2
  • -10⁴ ≤ x, y ≤ 10⁴
  • All points are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsVertical Mirror Line MediumA Stretch Divisible by k MediumFewest Guests by Lanyard Color MediumMagic 3×3 Blocks MediumSmallest Paddock Medium
loading Python…
Input
beacons=[[0, 0], [2, 0], [0, 2]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.