Valid Square

Try to solve the Valid Square problem.

Statement

Given the coordinates of four points P1P_1, P2P_2, P3P_3, and P4P_4 in 2D space, determine if these points form a square.

Each point PiP_i is represented as [xi, yi][x_i,\space y_i], and the points may be provided in any order.

A square is defined as having:

  • Four sides of equal positive length

  • Four right angles (90 degrees)

Constraints:

  • p1.length == p2.length == p3.length == p4.length == 2

  • 104-10^4\leq xi, yix_i, \space y_i 104\leq 10^4

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.