2857. Count Pairs of Points With Distance k Medium
1/**
2 * [2857] Count Pairs of Points With Distance k
3 *
4 * 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.
5 * 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.
6 * Return the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5
11 * Output: 2
12 * Explanation: We can choose the following pairs:
13 * - (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.
14 * - (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0
19 * Output: 10
20 * Explanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.
21 *
22 *
23 * Constraints:
24 *
25 * 2 <= coordinates.length <= 50000
26 * 0 <= xi, yi <= 10^6
27 * 0 <= k <= 100
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/count-pairs-of-points-with-distance-k/
33// discuss: https://leetcode.com/problems/count-pairs-of-points-with-distance-k/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn count_pairs(coordinates: Vec<Vec<i32>>, k: i32) -> i32 {
39 0
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_2857() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.