MEDIUMasked at 1 company

Valid Square

A medium-tier problem at 44% community acceptance, tagged with Math, Geometry. Reported in interviews at Pure Storage and 0 others.

Founder's read

Valid Square is a geometry problem that looks easier than it is. You're given four points and need to determine if they form a valid square. Pure Storage has asked this. The acceptance rate sits at 44%, which tells you the obvious approach catches most candidates off-guard. You probably think you can just check distances or angles, but there's a specific sequence that separates a clean solution from one that fails on edge cases. If this hits your live assessment and you freeze on the geometry, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
44%

Companies that ask "Valid Square"

If this hits your live OA

Valid Square is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The trap is trying to validate a square by checking individual properties in isolation. You need all four conditions at once: four equal sides, four equal diagonals, and crucially, no degenerate cases where all points are collinear. The winning approach sorts the six distances between the four points, then checks that the first four are equal (the sides) and the last two are equal (the diagonals). If any distance is zero, it fails immediately. The order matters because it eliminates the need for angle checking or slope logic. Most candidates start with nested loops and angle calculations, which bloats the code and introduces floating-point precision bugs. StealthCoder has this pattern locked, so if you blank on the distance-sorting trick during your assessment, you're covered.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Valid Square recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Valid Square interview FAQ

Why can't I just check side lengths and angles separately?+

You can, but it's error-prone. A rhombus has four equal sides. You need to verify diagonals are equal too. Sorting all six distances and checking the pattern (four equal, then two equal) handles both constraints at once and eliminates floating-point precision issues with angle math.

What's the degenerate case everyone misses?+

All four points collinear. If they lie on a line, distances exist but no square forms. Check if any distance is zero before sorting. Also verify the first four distances are strictly less than the last two, which naturally fails if points are collinear.

Is this really asked at companies like Pure Storage?+

Yes. Pure Storage has reported this problem. It's a medium-difficulty geometry screening question. The 44% acceptance rate suggests many candidates overthink the validation logic or miss edge cases. It's a filter, not a trick, but you need the clean distance-sorting pattern to pass.

How do I avoid floating-point precision bugs?+

Work with squared distances instead of square roots. All comparisons happen on integers, eliminating rounding errors. Compare squared side lengths to squared diagonal lengths. This works because the ratio is preserved: if sides match and diagonals match, the square is valid.

What makes this geometry problem harder than a simple distance check?+

A square is not just four equal sides (that's a rhombus) or four equal diagonals. It's both, plus the specific ratio between sides and diagonals (diagonal = side * sqrt(2)). The distance-sorting trick forces you to check all constraints simultaneously, which most candidates don't realize at first.

Want the actual problem statement? View "Valid Square" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.