2857. Count Pairs of Points With Distance k
Problem Statement
You are given a 2D integer array coordinates
and an integer k
, where coordinates[i] = [xi, yi]
are the coordinates of the ith
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:
Example 2:
Constraints:
2 <= coordinates.length <= 50000
0 <= xi, yi <= 106
0 <= k <= 100
Intuition
Links
https://leetcode.com/problems/count-pairs-of-points-with-distance-k/description/
Video Links
https://www.youtube.com/watch?v=1Hp6Hsghtno&ab_channel=AryanMittal
Approach 1:
C++
Approach 2:
C++
Approach 3:
C++
Approach 4:
C++
Similar Problems
Last updated