Problem
Ask
Submissions

Problem: Valid Square

Medium
30 min
Explore how to determine if four coordinates form a valid square by assessing side lengths and right angles. This lesson teaches you to apply geometric principles and coding patterns to solve this common interview problem effectively.

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

Problem
Ask
Submissions

Problem: Valid Square

Medium
30 min
Explore how to determine if four coordinates form a valid square by assessing side lengths and right angles. This lesson teaches you to apply geometric principles and coding patterns to solve this common interview problem effectively.

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