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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.