Ctrl K

Four Pins Make a Square

Medium
Four pins are stuck into a board at integer points a, b, c and d, each given as [x, y]. The pins are listed in arbitrary order, not necessarily the order you would walk around the shape. Return True if the pins sit at the corners of a square and False otherwise. A square has four equal sides of positive length and four right angles; its sides do not have to be parallel to the axes.
Example 1
a=[2, 0], b=[0, 1], c=[3, 2], d=[1, 3] → True

All sides have length √5 and both diagonals have length √10: it is a square tilted relative to the axes.

Example 2
a=[0, 0], b=[2, 0], c=[2, 1], d=[0, 1] → False

A 2 by 1 rectangle: the angles are right, but the sides differ.

Example 3
a=[5, 5], b=[5, 5], c=[5, 5], d=[5, 5] → False

All pins share one spot, and a square needs sides of positive length.

Constraints
  • a.length = b.length = c.length = d.length = 2
  • -10⁴ ≤ x, y ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsArea Under Two Rectangles MediumNo Inward Corners MediumLaser in a Mirror Room MediumSmallest Paddock MediumSmallest Rectangle of Pins Medium
loading Python…
Input
a=[2, 0], b=[0, 1], c=[3, 2], d=[1, 3]
Expected
True

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