Medium · Intervals

Is Square

Given an array points of exactly four points with integer coordinates, listed in any order, return true if they are the four corners of a square with positive side length (the square may be rotated) and false otherwise.

Examples

Example 1

{
  "points": [
    {"x": 0, "y": 0},
    {"x": 0, "y": 2},
    {"x": 2, "y": 2},
    {"x": 2, "y": 0}
  ]
}

Output: square

Example 2

{
  "points": [
    {"x": 0, "y": 0},
    {"x": 0, "y": 1},
    {"x": 3, "y": 1},
    {"x": 3, "y": 0}
  ]
}

Output: not a square

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Intervals problems