You are given points on a 2D plane with integer coordinates.
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.
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.
Follow-up:
1 <= N <= 2e4
(for the optimized discussion)
Clarify any additional assumptions you need (e.g., whether duplicates should be ignored by converting to a set).