← Pure Storage Interview Insights
I jumped straight to checking side lengths and forgot about the diagonal check.
First, clarify the problem constraints and edge cases (e.g., duplicate points, collinear points). Then, propose an efficient algorithm: compute all pairwise squared distances, sort them, and check that the first four are equal and positive, the last two are equal, and the last two are exactly twice the first four. Finally, discuss time and space complexity and test with examples.
Pro tip: Mention that using squared distances avoids floating-point precision issues, and explicitly handle duplicate points by checking that the smallest distance is greater than zero. Also, note that the sorted-distance property is a necessary and sufficient condition for a square.
Ask if the points are integers or floats, if duplicates are allowed, and if the square can be rotated. Confirm that all sides must be equal and all angles 90 degrees.
Decide to compute all six pairwise squared distances, sort them, and check the pattern: four equal small distances and two equal larger distances that are twice the small ones.
Write code that computes distances, sorts, and validates the pattern. Include a check that the smallest distance is > 0 to reject duplicate points.
State that the algorithm runs in O(1) time (since only 6 distances) and O(1) space. Walk through test cases: valid square, rectangle, rhombus, collinear points, duplicates.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.