Skip to content

Practice Count Pairs of Points With Distance k

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2857
LeetCode Problem

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.

Source: Count Pairs of Points With Distance k on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5
Output
2

# Example 2

Input
coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0
Output
10

Constraints

2 <= coordinates.length <= 50000
0 <= xi, yi <= 10^6
0 <= k <= 100

Related LeetCode Problems

Practice more problems similar to Count Pairs of Points With Distance k.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.