← Pure Storage Interview Insights
My first instinct was to sort the points and check distances, which works until you hit weird cases like three points on the same line or duplicate coordinates.
Clarify that the points are distinct and form a square if and only if the six pairwise squared distances consist of exactly two distinct values: four equal smaller sides and two equal larger diagonals, with the diagonal being twice the side squared. Then implement by computing all squared distances, sorting them, and checking the pattern [s, s, s, s, 2s, 2s] with s > 0.
Pro tip: Mention that using squared distances avoids floating-point precision issues, and explicitly handle duplicate points by ensuring the smallest distance is greater than zero. Also note that this method is O(1) since there are always four points.
Confirm that the four points are distinct and that a square must have non-zero side length. Ask if the points are guaranteed to be in any order and if integer coordinates are expected.
Explain that checking all six pairwise squared distances is sufficient: a valid square yields four equal sides and two equal diagonals, with diagonal squared = 2 * side squared.
Calculate the squared Euclidean distance between every pair of points, store them in a list, and sort the list in ascending order.
Check that the first four distances are equal and greater than zero, the last two are equal, and the last distance equals twice the first distance.
State that the algorithm runs in O(1) time and space because there are always exactly four points. Walk through a few test cases: a valid square, a rectangle, a rhombus, and duplicate points.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.