Given a vector of N positive integers and an integer X. The task is to find the frequency of X in vector.
 
Example 1: 
Input:
N = 5
vector = {1, 1, 1, 1, 1}
X = 1
Output: 
5
Explanation: Frequency of 1 is 5.
Your Task:
Your task is to complete the function findFrequency() which should count the frequency of X and return it.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:
#User function Template for python3

"""
You're given an array (arr) of length n
Return the frequency of element x in the given array
"""
def findFrequency (arr, n, x):
    # Your Code Here


Solutions:
def findFrequency(arr, n, x):
	c = 0
	for i in arr:
		if i == x:
			c += 1
	return c


def findFrequency(arr, n, x):
	return arr.count(x)


def findFrequency(arr, n, x):
	mp = {}
	for i in range(n):
		if arr[i] in mp:
			mp[arr[i]] += 1
		else:
			mp[arr[i]] = 1
	if x not in mp:
		return 0
	return mp[x]


def findFrequency(arr, n, x):
	d = {}
	for i in range(n):
		if arr[i] in d:
			d[arr[i]] += 1
		else:
			d[arr[i]] = 1
	if x in d:
		return d[x]
	return 0


def findFrequency(arr, n, x):
	count = 0
	for i in range(n):
		if arr[i] == x:
			count += 1
	return count


def findFrequency(arr, n, x):
	d = {}
	for item in arr:
		if item in d:
			d[item] += 1
		else:
			d[item] = 1
	if x in d:
		return d[x]
	else:
		return 0


def findFrequency(arr, n, x):
	dt = {}
	for each in arr:
		if each in dt:
			dt[each] += 1
		else:
			dt[each] = 1
	if x in dt:
		return dt[x]
	return 0


def findFrequency(arr, n, x):
	count = 0
	for num in arr:
		if num == x:
			count += 1
	return count


def findFrequency(arr, n, x):
	list1 = list(arr)
	return list1.count(x)


def findFrequency(arr, n, x):
	hash = {}
	for elem in arr:
		if elem == x:
			if elem not in hash:
				hash[elem] = 1
			else:
				hash[elem] += 1
	if x in hash:
		return hash[x]
	else:
		return 0


def findFrequency(arr, n, x):
	counter = 0
	for item in arr:
		if item == x:
			counter += 1
	return counter


def findFrequency(arr, n, x):
	dict1 = {}
	for i in arr:
		if i not in dict1:
			dict1[i] = 1
		else:
			dict1[i] += 1
	if x not in arr:
		return 0
	else:
		return dict1[x]


def findFrequency(arr, n, x):
	d = {}
	for i in arr:
		d[i] = 0
	for i in arr:
		d[i] = d[i] + 1
	for (k, v) in d.items():
		if k == x:
			return v
	return 0


def findFrequency(arr, n, x):
	hashmap = {}
	for ele in arr:
		if ele not in hashmap:
			hashmap[ele] = 1
		else:
			hashmap[ele] += 1
	c = 0
	for (k, v) in hashmap.items():
		if k == x:
			c = v
		else:
			continue
	return c


def findFrequency(arr, n, x):
	c = 0
	for i in range(n):
		if arr[i] == x:
			c += 1
		else:
			continue
	return c


def findFrequency(arr, n, x):
	p = 0
	for X in arr:
		if X == x:
			p += 1
	return p


def findFrequency(arr, n, x):
	arr.sort()
	arr.append(-222)
	i = 0
	while arr[i] != x:
		if arr[i] == -222:
			break
		else:
			i = i + 1
	count = 0
	while arr[i] == x:
		count += 1
		i = i + 1
	return count


from operator import countOf

def findFrequency(arr, n, x):
	return countOf(arr, x)


def findFrequency(arr, n, x):
	a = []
	for i in arr:
		if i == x:
			a.append(i)
	return len(a)


def findFrequency(arr, n, x):
	f = 0
	for i in arr:
		if x == i:
			f += 1
		else:
			pass
	return f


from collections import defaultdict

def findFrequency(arr, n, x):
	rec = defaultdict(int)
	for a in arr:
		rec[a] += 1
	return rec[x]