Your are given N pairs of alphabets and a string S of size M. Find the number of occurence of the alphabet pairs in S.
Example 1:
Input :
N = 3
Arr[] = {('A','G'),('d','i'),('P','o')}
M = 5
S = "APiod"
Output : 2
Explanation:
There are 3 pairs (A G), (d i) & (P o)
and a string APiod of length 5. Of the
3 pairs, only 2 of them (d i) & (P o)
appear in the string, so the answer is
2.
Example 2:
Input :
N = 1
Arr[] = {('r','e')}
M = 3
S= "ghe"
Output : 0
Your Task:
The input is already taken care of by the driver code. You only need to complete the function count_pairs() that takes an array of character arr denoting the N pairs of charater, string (S),  N, M, and return the number of pairs. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(M).
Constraints:
1<=N<=10^{5}
2<=M<=50

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(M).

Starter code:
#User function Template for python3
class Solution:
	
	def count_pair( self, arr , s, n, m ): 
		#Complete the function

Solutions:
class Solution:

	def count_pair(self, arr, s, n, m):
		out = [0 for i in range(n)]
		for i in range(n):
			if arr[i] in s:
				out[i] += 1
		cnt = 0
		for i in range(0, n, 2):
			if out[i] > 0 and out[i + 1] > 0:
				cnt += 1
		return cnt


class Solution:

	def count_pair(self, arr, s, n, m):
		count = 0
		for i in range(0, n, 2):
			if arr[i] in s:
				if arr[i + 1] in s:
					count += 1
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		c = 0
		for i in range(0, len(arr), 2):
			if arr[i] in s and arr[i + 1] in s:
				c += 1
		return c


class Solution:

	def count_pair(self, arr, s, n, m):
		count = 0
		for index in range(0, n, 2):
			count += 1 if arr[index] in s and arr[index + 1] in s else 0
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		res = []
		for i in arr:
			for j in i:
				res.append(j)
		cou = 0
		for i in range(0, len(res), 2):
			if res[i] in s and res[i + 1] in s:
				cou += 1
		return cou


class Solution:

	def count_pair(self, arr, s, n, m):
		setti = set(s)
		count = 0
		for i in range(0, n, 2):
			count += arr[i] in setti and arr[i + 1] in setti
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		se = set()
		for i in s:
			se.add(i)
		count = 0
		n = len(arr)
		for i in range(0, n, 2):
			if arr[i] in se and arr[i + 1] in se:
				count += 1
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		i = 0
		count = 0
		while i < n:
			if arr[i] in s and arr[i + 1] in s:
				count += 1
			i += 2
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		count = 0
		d = {}
		for i in s:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		x = []
		c = []
		for i in arr:
			c.append(i)
			if len(c) == 2:
				x.append(c)
				c = []
		for i in x:
			if i[0] in d and i[1] in d:
				count += 1
		return count


class Solution:

	def count_pair(self, arr, s, n, m):
		c = 0
		for i in range(0, len(arr), 2):
			if arr[i] in s and arr[i + 1] in s:
				c += 1
		return c
for _ in range(0, int(input())):
	(n, m) = map(int, input().strip().split())
	arr = list(map(str, input().strip().split()))
	s = input()
	ob = Solution()
	print(ob.count_pair(arr, s, 2 * n, m))


class Solution:

	def count_pair(self, arr, s, n, m):
		count = 0
		lst = list(s)
		for itr in range(0, n, 2):
			if arr[itr] in lst and arr[itr + 1] in lst:
				count += 1
		return count
for _ in range(0, int(input())):
	(n, m) = map(int, input().strip().split())
	arr = list(map(str, input().strip().split()))
	s = input()
	ob = Solution()
	print(ob.count_pair(arr, s, 2 * n, m))


class Solution:

	def count_pair(self, arr, s, n, m):
		x = [0] * 128
		ans = 0
		for i in s:
			x[ord(i)] = 1
		for i in range(0, n, 2):
			if x[ord(arr[i])] == 1 and x[ord(arr[i + 1])] == 1:
				ans += 1
		return ans


class Solution:

	def count_pair(self, arr, s, n, m):
		d = dict()
		for i in s:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		c = 0
		i = 0
		while i < len(arr) - 1:
			if arr[i] in d and arr[i + 1] in d:
				if d[arr[i]] > 0 and d[arr[i + 1]] > 0:
					c = c + 1
			i = i + 2
		return c


class Solution:

	def count_pair(self, arr, s, n, m):
		sum = 0
		x = 0
		for j in range(0, n):
			if s.find(arr[j]) != -1:
				x += 1
			if (j + 1) % 2 == 0:
				if x == 2:
					sum += 1
				x = 0
		return sum


class Solution:

	def count_pair(self, arr, s, n, m):
		x = 0
		myArr = []
		for j in range(0, n):
			if j % 2 == 0:
				i = 0
			if arr[j] in s:
				i += 1
			if i == 2:
				x += 1
		return x


import numpy as np

class Solution:

	def count_pair(self, arr, s, n, m):
		count = 0
		npArr = np.array(arr)
		newArr = np.array_split(npArr, len(arr) / 2)
		for x in newArr:
			if s.find(x[0]) > -1 and s.find(x[1]) > -1:
				count += 1
		return count