← Pure Storage Interview Insights

Pure Storage·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pure Storage coding round, just the one geometry problem. Pretty niche but manageable once you figure out the right approach to avoid floating point headaches.

Questions Asked (1)

Q1

Given four 2D points, determine whether they form a valid square (axis-aligned or rotated).

Algorithms & Data Structures
Author's notes

My first instinct was to do something with slopes and distances and I immediately started second-guessing myself on floating point precision.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Compute all six pairwise squared distances between the four points. For a valid square, these distances must consist of exactly four equal smaller values (the sides) and two equal larger values (the diagonals), with the diagonal being exactly twice the side. This method elegantly handles both axis-aligned and rotated squares without needing to check angles or slopes.

Pro tip: Mention that using squared distances avoids floating-point precision issues and that this approach is O(1) since the number of points is fixed. Also, clarify that the points must be distinct and form a non-degenerate square.

1. Clarify assumptions and edge cases

Confirm that the four points are distinct and that a valid square must have non-zero side length. Discuss how to handle duplicate points or collinear points.

2. Compute all pairwise squared distances

Calculate the squared Euclidean distance between every pair of points (6 distances total). Use squared distances to avoid square roots and floating-point errors.

3. Sort or count the distances

Sort the six distances or use a hash map to count frequencies. For a square, you should see exactly four equal smaller distances and two equal larger distances.

4. Verify the square property

Check that the four smaller distances are equal, the two larger distances are equal, and the larger distance is exactly twice the smaller distance (diagonal^2 = 2 * side^2).

5. Return the result and discuss complexity

Return true if all conditions are met, false otherwise. Explain that the algorithm runs in O(1) time and space since the input size is fixed.

Key Points to Mention

  • Use squared distances to avoid floating-point precision issues.
  • For a square, the six pairwise distances must be four equal sides and two equal diagonals.
  • The diagonal squared must be exactly twice the side squared.
  • The approach works for any orientation (axis-aligned or rotated).
  • Time and space complexity are O(1) because the number of points is constant.
  • Edge cases: duplicate points, zero-area (degenerate) squares, and collinear points.

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