You are given a stream of points on the X-Y plane. Design an algorithm that:
An axis-aligned square has all four sides parallel to the x- and y-axes.
Implement the DetectSquares class:
DetectSquares() - initializes the object.add(point) - adds a new point [x, y] to the data structure.count(point) - counts the number of axis-aligned squares that include point as a corner.(3,10) (11,10) (3,2) (11,2) <- query point
Input: ["DetectSquares","add","add","add","count","count","add","count"]
[[],[[3,10]],[[11,2]],[[3,2]],[[11,10]],[[14,8]],[[11,2]],[[11,10]]]
Output: [null,null,null,null,1,0,null,2]
Explanation: After adding (3,10), (11,2), (3,2): count([11,10]) finds 1 square. count([14,8]) finds 0. After adding a duplicate (11,2): count([11,10]) finds 2 squares.
0 <= x, y <= 10003000 calls will be made to add and count.add (3,10),(11,2),(3,2) then count([11,10])