Count Pairs of Points With Distance k
You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the i^th point in a 2D plane.
We define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2), where XOR is the bitwise XOR operation.
Return the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.
Example 1
Input
coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5Output
2Pairs (0,1) and (2,3) both have XOR distance 5.
Example 2
Input
coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0Output
10Any two points have distance 0, and there are 10 ways to choose two of the five points.
Constraints
- 2 <= coordinates.length <= 50000
- 0 <= xi, yi <= 10^6
- 0 <= k <= 100