← 返回 capitalone 的题目列表Count Point Pairs with Manhattan Distance at Least K
类型:online_judge
capitalone
Given a set of points in a 2D plane, two points are considered a pair if their Manhattan distance is sufficiently close. Design an algorithm to find the total number of such qualifying point pairs. You need to implement a function countPairs that takes a two-dimensional integer array points and an integer k, where points[i] = [x_i, y_i] represents a point on the plane, and k is the minimum Manhattan distance for two points to be considered a qualifying pair. The function should return the total number of qualifying point pairs that can be formed.
Input:
points: a two-dimensional integer array representing multiple points, 1 <= points.length <= 10^5, -10^4 <= x_i, y_i <= 10^4
k: an integer, 1 <= k <= 10^4
Output: Return the total number of qualifying point pairs.
Example:
countPairs([[1, 3], [3, 4], [2, -1]], 3) # Returns 2
In this example, the Manhattan distance between points (1, 3) and (3, 4) is 3, and the Manhattan distance between points (3, 4) and (2, -1) is 3, resulting in two qualifying point pairs.
Example
Input
[[1, 3], [3, 4], [2, -1]], 3