PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Purestorage

Determine whether points form squares

Last updated: Apr 27, 2026

Quick Overview

This question evaluates computational geometry, combinatorial counting, and algorithmic optimization skills by requiring validation of a non-degenerate square from four 2D integer points and counting distinct squares in a larger point set, and it falls under the Coding & Algorithms category.

  • medium
  • Purestorage
  • Coding & Algorithms
  • Software Engineer

Determine whether points form squares

Company: Purestorage

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem: Square detection and counting from point coordinates You are given points on a 2D plane with integer coordinates. ### Part A — Validate a single square Given **exactly 4 points** `[(x1,y1), (x2,y2), (x3,y3), (x4,y4)]`, determine whether these 4 points can be the vertices of a **non-degenerate square** (square may be rotated; sides are not necessarily axis-aligned). **Output:** `true` if they form a square, otherwise `false`. ### Part B — Count squares in a set (with optimization) Given **N points** (may contain duplicates; treat duplicates as separate inputs but they should not create degenerate “squares”), count how many **distinct squares** can be formed whose **4 vertices are all present in the set**. - A square is considered the same regardless of the order of its vertices. - Squares may be rotated. **Follow-up:** 1. Describe a brute-force approach (e.g., around \(O(n^4)\)). 2. Improve it to about \(O(n^3)\). 3. Further improve to about \(O(n^2)\) time (assume hash set / hash map lookups are \(O(1)\) average). ### Constraints (assume typical interview constraints) - `1 <= N <= 2e4` (for the optimized discussion) - Coordinates fit in 32-bit signed integers Clarify any additional assumptions you need (e.g., whether duplicates should be ignored by converting to a set).

Quick Answer: This question evaluates computational geometry, combinatorial counting, and algorithmic optimization skills by requiring validation of a non-degenerate square from four 2D integer points and counting distinct squares in a larger point set, and it falls under the Coding & Algorithms category.

Purestorage logo
Purestorage
Nov 5, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
4
0

Problem: Square detection and counting from point coordinates

You are given points on a 2D plane with integer coordinates.

Part A — Validate a single square

Given exactly 4 points [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], determine whether these 4 points can be the vertices of a non-degenerate square (square may be rotated; sides are not necessarily axis-aligned).

Output: true if they form a square, otherwise false.

Part B — Count squares in a set (with optimization)

Given N points (may contain duplicates; treat duplicates as separate inputs but they should not create degenerate “squares”), count how many distinct squares can be formed whose 4 vertices are all present in the set.

  • A square is considered the same regardless of the order of its vertices.
  • Squares may be rotated.

Follow-up:

  1. Describe a brute-force approach (e.g., around O(n4)O(n^4)O(n4) ).
  2. Improve it to about O(n3)O(n^3)O(n3) .
  3. Further improve to about O(n2)O(n^2)O(n2) time (assume hash set / hash map lookups are O(1)O(1)O(1) average).

Constraints (assume typical interview constraints)

  • 1 <= N <= 2e4 (for the optimized discussion)
  • Coordinates fit in 32-bit signed integers

Clarify any additional assumptions you need (e.g., whether duplicates should be ignored by converting to a set).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Purestorage•More Software Engineer•Purestorage Software Engineer•Purestorage Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.