Count Colliding Object Pairs
Problem statement
Each row of centers contains integer coordinates [x, y] for one object; several objects may share a center.
Two objects collide exactly when both |x1 - x2| <= 2 and |y1 - y2| <= 2. Return the number of unordered colliding index pairs.
Function
countCollidingPairs(centers: int[][]) → longExamples
Example 1
centers = [[1,1],[2,2],[0,4]]return = 2The first and second centers collide, and the second and third centers collide.
Example 2
centers = [[0,0],[0,0]]return = 1Objects sharing a center collide.
Constraints
0 <= centers.length <= 5000- Every row contains two integers.