← Pure Storage Interview Insights

Pure Storage·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pure Storage coding screen, geometry problem, nothing too wild but it required more careful thinking than I expected going in.

Questions Asked (1)

Q1

Given four 2D points in no particular order, write a function that returns true if they form a valid square (all sides equal, all right angles) and false otherwise.

Algorithms & Data Structures
Author's notes

I jumped straight to checking side lengths and forgot about the diagonal check.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Clarify requirements and edge cases

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.

2. Choose an efficient algorithm

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.

3. Implement and handle edge cases

Write code that computes distances, sorts, and validates the pattern. Include a check that the smallest distance is > 0 to reject duplicate points.

4. Analyze complexity and test

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.

Key Points to Mention

  • Use squared distances to avoid floating-point precision issues.
  • Sort the six pairwise squared distances and check the pattern: d, d, d, d, 2d, 2d with d > 0.
  • Handle duplicate points by ensuring the smallest distance is greater than zero.
  • Time complexity is O(1) because the number of points is fixed; space complexity is O(1).
  • Alternative approach: check that the four points have exactly two unique distances from each point, but the sorted-distance method is simpler and more robust.
  • Test with edge cases: all points same, three collinear, rectangle, rhombus, and rotated square.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.