Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

operations =
arguments =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

For query point (x,y), pick another point (x2,y) on same row; it defines side length d. Then check the two possible squares above/below.

Approach

Store counts of points and counts by row y -> {x: count}. On count([x,y]), iterate all x2 in same row. For each, compute d=x2-x and accumulate counts for corners (x,y±d) and (x2,y±d).

Why it works

Axis-aligned square is uniquely determined by choosing the second point on the same horizontal line (sets side length and direction).

Code
Loading...
Complexity
Time: Add: O(1), Count: O(#points on row y)
Space: O(N)
Solution
Updated: 2026-02-23

Idea

For query point (x,y), pick another point (x2,y) on same row; it defines side length d. Then check the two possible squares above/below.

Approach

Store counts of points and counts by row y -> {x: count}. On count([x,y]), iterate all x2 in same row. For each, compute d=x2-x and accumulate counts for corners (x,y±d) and (x2,y±d).

Why it works

Axis-aligned square is uniquely determined by choosing the second point on the same horizontal line (sets side length and direction).

Code
Loading...
Complexity
Time: Add: O(1), Count: O(#points on row y)
Space: O(N)