From e38bc650718863145d4fdc5014f8a3cc04237f9c Mon Sep 17 00:00:00 2001 From: Adarsh Santoria Date: Tue, 3 Oct 2023 13:11:32 +0530 Subject: [PATCH] Create Count Pairs of Points With Distance k.py --- .../Count Pairs of Points With Distance k.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode Problems/Count Pairs of Points With Distance k.py diff --git a/LeetCode Problems/Count Pairs of Points With Distance k.py b/LeetCode Problems/Count Pairs of Points With Distance k.py new file mode 100644 index 0000000..ab0efc3 --- /dev/null +++ b/LeetCode Problems/Count Pairs of Points With Distance k.py @@ -0,0 +1,14 @@ +from collections import defaultdict + +class Solution: + def countPairs(self, coordinates, k): + m1 = defaultdict(int) + ans = 0 + for i in range(len(coordinates)): + for j in range(k + 1): + a = coordinates[i][0] ^ j + b = coordinates[i][1] ^ (k - j) + if (a, b) in m1: + ans += m1[(a, b)] + m1[(coordinates[i][0], coordinates[i][1])] += 1 + return ans