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 withpointas 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 == 20 <= x, y <= 1000- At most
5000addandcountcalls 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]]