You are given 3 different arrays A, B, and C of the same size N. Find the number of indexes i such that:
A_{i} = B_{i }+ C_{k }
where k lies between [1, N].
 
Example 1:
Input: N = 3
A = {1, 2, 3}
B = {3, 2, 4}
C = {0, 5, -2}
Output: 2
Explaination: The possible i's are 0 and 1. 
1 = 3 + (-2) and 2 = 2 + 0.
 
Your Task:
You do not need to read input or print anything. Your task is to complete the function pairCount() which takes the value N and the arrays A, B, and C as input parameters and returns the number of possible indices.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 ≤ N ≤ 10^{4}
1 ≤ A[i], B[i] ≤ 100
-100 ≤ C[i] ≤ 100

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def pairCount(self, N, A, B, C):

        # code here

Solutions:
class Solution:

	def pairCount(self, N, A, B, C):
		s = set(C)
		c = 0
		for i in range(N):
			temp = A[i] - B[i]
			if temp in C:
				c += 1
		return c


from collections import Counter

class Solution:

	def pairCount(self, N, A, B, C):
		c = Counter()
		for i in range(N):
			c[A[i] - B[i]] += 1
		count = 0
		for item in set(C):
			count += c[item]
		return count


class Solution:

	def pairCount(self, N, A, B, C):
		c = 0
		d = {}
		for i in C:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in range(N):
			d1 = A[i] - B[i]
			try:
				if d[d1] > 0:
					c += 1
			except:
				pass
		return c


class Solution:

	def pairCount(self, N, A, B, C):
		count = 0
		for i in range(N):
			if A[i] - B[i] in C:
				count += 1
		return count


class Solution:

	def pairCount(self, N, A, B, C):
		Set = set()
		for i in range(len(C)):
			Set.add(C[i])
		cnt = 0
		for i in range(N):
			if A[i] - B[i] in Set:
				cnt += 1
		return cnt


class Solution:

	def pairCount(self, N, A, B, C):
		counter = {}
		for i in C:
			counter.setdefault(i, 0)
			counter[i] += 1
		c = 0
		for i in range(0, N):
			if A[i] - B[i] in counter:
				c += 1
		return c


class Solution:

	def pairCount(self, N, A, B, C):
		d = {}
		for i in C:
			if i not in d:
				d[i] = 1
		for i in range(N):
			A[i] = A[i] - B[i]
		res = 0
		for i in A:
			try:
				if d[i]:
					res += 1
			except:
				pass
		return res


class Solution:

	def pairCount(self, N, A, B, C):
		d = {}
		for i in C:
			if i not in d:
				d[i] = 1
		for i in range(N):
			A[i] = A[i] - B[i]
		res = 0
		for i in A:
			if i in d.keys():
				res += 1
		return res


from collections import defaultdict

class Solution:

	def pairCount(self, N, A, B, C):
		d = defaultdict(lambda : 0)
		for i in C:
			d[i] = 1
		c = 0
		for i in range(N):
			if d[A[i] - B[i]]:
				c += 1
		return c


class Solution:

	def pairCount(self, N, A, B, C):
		a = set(C)
		c = 0
		for i in range(len(A)):
			if A[i] - B[i] in C:
				c += 1
		return c


class Solution:

	def pairCount(self, N, A, B, C):
		d = {}
		for i in range(N):
			if d.get(C[i], None) is None:
				d[C[i]] = 1
			else:
				d[C[i]] += 1
		c = 0
		for i in range(N):
			if d.get(A[i] - B[i], None) is not None:
				c += 1
		return c


class Solution:

	def pairCount(self, N, A, B, C):
		c = 0
		ans = 0
		d = {}
		for i in range(N):
			d[C[i]] = 1
		for i in range(N):
			if A[i] - B[i] in d:
				c += 1
		return c