Tap here to switch tabs
Problem
Submissions

Problem: Detect Squares

Try to solve the Detect Squares problem.

Statement

Design a data structure that receives a stream of points on the XX-YY plane and supports querying the number of axis-aligned squares that can be formed.

Implement the DetectSquares class:

  • DetectSquares() initializes the object with an empty set of points.

  • void add(int[] point) adds a new point point = [x, y] into the data structure. Duplicate points are permitted and are considered distinct instances.

  • int count(int[] point) returns the number of ways to choose 33 points from the data structure such that, together with the query point = [x, y], they form an axis-aligned square of positive area.

Note: An axis-aligned square has all 44 sides parallel or perpendicular to the coordinate axes.

Constraints:

  • point.length =2= 2

  • 0≤x,y≤10000 \leq x, y \leq 1000

  • At most 30003000 calls in total will be made to add and count.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Detect Squares

Try to solve the Detect Squares problem.

Statement

Design a data structure that receives a stream of points on the XX-YY plane and supports querying the number of axis-aligned squares that can be formed.

Implement the DetectSquares class:

  • DetectSquares() initializes the object with an empty set of points.

  • void add(int[] point) adds a new point point = [x, y] into the data structure. Duplicate points are permitted and are considered distinct instances.

  • int count(int[] point) returns the number of ways to choose 33 points from the data structure such that, together with the query point = [x, y], they form an axis-aligned square of positive area.

Note: An axis-aligned square has all 44 sides parallel or perpendicular to the coordinate axes.

Constraints:

  • point.length =2= 2

  • 0≤x,y≤10000 \leq x, y \leq 1000

  • At most 30003000 calls in total will be made to add and count.