Count Axis-Aligned and Rotated Squares
Problem statement
Each row in points is an integer coordinate. Count all squares whose four vertices occur in the input, including rotated squares.
Duplicate coordinates represent distinct point occurrences. A square using coordinates with frequencies f1..f4 contributes their product. Return the total number of occurrence-level squares.
Function
countSquares(points: int[][]) → longExamples
Example 1
points = [[0,0],[1,0],[1,1],[0,1]]return = 1The four points form one axis-aligned square.
Example 2
points = [[0,1],[1,0],[2,1],[1,2]]return = 1The four points form one rotated square.
Constraints
0 <= points.length <= 2000.- Coordinates fit signed 32-bit integers.
- The answer fits signed 64-bit range.
Source note: Author-written prompt excerpt retained for source fidelity.