← Pure Storage Interview Insights
My first instinct was to check slopes and distances separately and I immediately started going down a path involving floating point comparisons which felt wrong even as I was saying it.
Clarify that the points are distinct and form a square if all sides are equal and diagonals are equal and longer than sides. Compute all six pairwise squared distances, sort them, and check that the first four are equal and positive, and the last two are equal and exactly twice the side squared. Alternatively, use a geometric property like checking center and vertices, but the distance method is simpler and robust.
Pro tip: Mention that using squared distances avoids floating-point precision issues, and explicitly handle duplicate points or degenerate cases (e.g., all points collinear) by ensuring the side length is greater than zero.
Confirm that the four points are distinct and that a valid square must have non-zero area. Discuss how to handle duplicate points or collinear points.
Compute all six pairwise squared distances between the four points. This avoids square roots and floating-point comparisons.
Sort the six distances. For a square, the four smallest must be equal (side length squared) and positive, and the two largest must be equal and exactly twice the side squared (diagonal squared).
Write the function, then test with axis-aligned, rotated, and invalid cases (e.g., rectangle, rhombus, collinear points).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.