Count Axis-Aligned and Rotated Squares
Updated
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.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Max Points on a LineUber · PHONE SCREENUber interview questions
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Max Points on a LineMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREENOpenAI interview questions
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Best-Fit Plane Normal from 3D PointsThe Voleon Group · PHONE SCREEN
- Parse, Normalize, and Combine PolynomialsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Maximum Visible DronesAnduril · PHONE SCREENAnduril interview questions
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions