← Pure Storage Interview Insights

Pure Storage·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Pure Storage coding interview, one problem the whole session. The question was geometric and I hadn't seen anything quite like it before, so it took me a minute to even figure out what structure to reach for.

Questions Asked (1)

Q1

Given a set of distinct points on a 2D plane, count how many squares can be formed using exactly four of those points as vertices. The squares can be axis-aligned or rotated at any angle.

Algorithms & Data Structures
Author's notes

My first instinct was to brute-force all combinations of four points and check each one, which is obviously way too slow.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the points are distinct and integer coordinates, then propose an O(n^2) algorithm using a hash set of points. For each pair of points, treat them as a potential side or diagonal of a square, compute the other two vertices, and check if they exist in the set. Avoid double-counting by considering each square exactly once.

Pro tip: Mention that you can avoid double-counting by only considering pairs where the first point is lexicographically smaller than the second, or by dividing the final count by 4 if each square is counted four times. Also, discuss handling large coordinates and potential overflow.

1. Clarify assumptions and constraints

Ask about input size, coordinate ranges, and whether points are distinct. Confirm that squares can be rotated arbitrarily and that only exactly four points can form a square.

2. Choose a representation and data structure

Store all points in a hash set for O(1) lookup. Consider encoding points as tuples or integers to avoid hash collisions.

3. Iterate over pairs and compute other vertices

For each pair of points, compute the two possible squares that have this pair as a side (or diagonal). Use vector rotation to find the other two vertices.

4. Check existence and count

For each computed vertex, check if it exists in the set. If both exist, increment the count. Ensure each square is counted only once by enforcing an ordering condition on the pair.

5. Analyze complexity and edge cases

Discuss time complexity O(n^2) and space O(n). Handle edge cases like collinear points, duplicate points (if not distinct), and large coordinates causing overflow.

Key Points to Mention

  • Hash set for O(1) point lookup
  • Vector rotation to compute square vertices
  • Avoiding double-counting by ordering pairs or dividing by 4
  • Time complexity O(n^2) and space O(n)
  • Handling integer overflow with large coordinates
  • Edge cases: collinear points, duplicate points, and squares of zero area

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