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.

Detect Squares

Medium

You are given a stream of points (x, y) on a 2D plane. Implement the class DetectSquares that supports:

  • void add(int[] point) Adds a new point to the data structure.
  • int count(int[] point) Counts the number of squares that can be formed with point as one of the corners and the other three corners in the data structure. The sides of the squares should be parallel to the axes.

 

Constraints:

  • point.length == 2
  • 0 <= x, y <= 1000
  • At most 5000 add and count calls in total.

Examples

  • ["DetectSquares","add","add","add","count","count","add","count"]
  • [[],[3,10],[11,2],[3,2],[11,10],[14,8],[11,2],[11,10]]

Detect Squares

Medium

You are given a stream of points (x, y) on a 2D plane. Implement the class DetectSquares that supports:

  • void add(int[] point) Adds a new point to the data structure.
  • int count(int[] point) Counts the number of squares that can be formed with point as one of the corners and the other three corners in the data structure. The sides of the squares should be parallel to the axes.

 

Constraints:

  • point.length == 2
  • 0 <= x, y <= 1000
  • At most 5000 add and count calls in total.

Examples

  • ["DetectSquares","add","add","add","count","count","add","count"]
  • [[],[3,10],[11,2],[3,2],[11,10],[14,8],[11,2],[11,10]]