Given a sorted array A[] having 10 elements which contain 6 different numbers in which only 1 number is repeated five times. Your task is to find the duplicate number using two comparisons only.
Example 1:
Input: 
A[] = {1, 1, 1, 1, 1, 5, 7, 10, 20, 30}
Output: 1
Example 2:
Input: 
A[] = {1, 2, 3, 3, 3, 3, 3, 5, 9, 10}
Output: 3
Your Task:  
You don't need to read input or print anything. Your task is to complete the function findDuplicate() which takes the array A[], as inputs and returns the required duplicate element.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
Size of the array A[] = 10
1 ≤ A[] ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

def findDuplicate(A):
    # Your code goes here
    






    

Solutions:
from collections import Counter

def findDuplicate(A):
	a = Counter(A)
	for ele in a:
		if a[ele] > 1:
			return ele


def findDuplicate(A):
	b = set(A)
	c = list(b)
	d = sum(A)
	e = sum(c)
	f = len(A)
	g = len(c)
	h = d - e
	i = f - g
	return int(h / i)


def findDuplicate(arr):
	temp = arr[9 // 2]
	if arr[13 // 2] == temp:
		return arr[13 // 2]
	if arr[4 // 2] == temp:
		return arr[4 // 2]
	return arr[9]


def findDuplicate(A):
	if A[3] == A[4]:
		return A[3]
	if A[5] == A[6]:
		return A[5]


def findDuplicate(A):
	A.sort()
	l1 = []
	for i in range(0, len(A)):
		if A[i] == A[i + 1]:
			return A[i]


import collections

def findDuplicate(A):
	dict1 = collections.Counter(A)
	for i in dict1:
		if dict1[i] == 5:
			return i


def findDuplicate(A):
	for i in range(len(A)):
		if A[i] == A[i + 1]:
			return A[i]


def findDuplicate(A):
	if A[3] == A[4]:
		return A[3]
	elif A[4] == A[5]:
		return A[4]
	return A[5]


def findDuplicate(A):
	a = set(A)
	for i in a:
		if A.count(i) == 5:
			return i


def findDuplicate(A):
	d = {}
	for i in A:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for (i, j) in d.items():
		if j == 5:
			return i


def findDuplicate(A):
	A.sort()
	if A[3] == A[4]:
		return A[3]
	elif A[4] == A[5]:
		return A[4]
	else:
		return A[5]


def findDuplicate(A):
	if A[3] == A[4]:
		return A[4]
	if A[6] == A[7]:
		return A[7]


from collections import Counter

def findDuplicate(A):
	d1 = Counter(A)
	l1 = [key for (key, value) in d1.items() if d1[key] == 5]
	return l1[0]


def findDuplicate(A):
	if A[0] == A[4]:
		return A[0]
	return A[5]


def findDuplicate(A):
	d = dict()
	for ele in A:
		d[ele] = 0
	for ele in A:
		d[ele] = d[ele] + 1
	for (k, v) in d.items():
		if v >= 2:
			return k


def findDuplicate(a):
	if a[3] == a[4]:
		return a[3]
	elif a[4] == a[5]:
		return a[4]
	else:
		return a[5]


def findDuplicate(arr):
	test = {}
	for i in range(0, 10):
		if arr[i] in test.keys():
			test[arr[i]] += 1
		if arr[i] not in test.keys():
			test[arr[i]] = 1
	for i in test:
		if test[i] == 5:
			return i


def findDuplicate(a):
	if a[3] == a[4]:
		return a[3]
	if a[4] == a[5]:
		return a[4]
	return a[5]


def findDuplicate(a):
	for i in range(9):
		if a[i] == a[i + 1]:
			return a[i]


def findDuplicate(A):
	return A[4] if A[4] == A[3] else A[5]


def findDuplicate(A):
	elements = {x: 0 for x in A}
	for i in A:
		elements[i] += 1
		if elements[i] == 5:
			return i


def findDuplicate(A):
	n = len(A) // 2
	if A[n] == A[n + 1]:
		return A[n]
	return A[n - 1]


def findDuplicate(A):
	d = {}
	for i in A:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	m = max(d.values())
	for (i, j) in d.items():
		if j == m:
			return i


def findDuplicate(A):
	n = len(A)
	val = []
	for i in A:
		if i not in val:
			val.append(i)
		else:
			return i
			break


def findDuplicate(A):
	mid = 5
	if A[mid] == A[mid + 1]:
		return A[mid]
	if A[mid - 1] == A[mid - 2]:
		return A[mid - 1]


def findDuplicate(A):
	for i in range(0, 10):
		if A.count(A[i]) == 5:
			return A[i]


def findDuplicate(A):
	for i in range(5):
		if A[i] == A[i + 1]:
			return A[i]
	return A[i + 1]


def findDuplicate(a):
	if a[0] != a[4]:
		return a[5]
	else:
		return a[0]


def findDuplicate(A):
	for i in A:
		if A.count(i) > 1:
			return i


def findDuplicate(A):
	A = sorted(A)
	mid = len(A) // 2
	if A.count(A[mid - 1]) == 5:
		return A[mid - 1]
	elif A.count(A[mid + 1]) == 5:
		return A[mid + 1]
	else:
		return A[mid]


def findDuplicate(A):
	t = A[4]
	m = A[5]
	A.remove(A[4])
	if t in A:
		return t
	else:
		return m


def findDuplicate(A):
	ans = -1
	if A[4] != A[5]:
		if A[0] == A[4]:
			ans = A[4]
		else:
			ans = A[5]
	else:
		ans = A[4]
	return ans


def findDuplicate(A):
	d = {}
	for i in A:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	for i in d:
		if d[i] == 5:
			return i


def findDuplicate(A):
	if A[0] == A[1]:
		return A[0]
	elif A[-1] == A[-2]:
		return A[-1]
	else:
		return A[2]


def findDuplicate(A):
	a = list(set(A))
	for i in a:
		if A.count(i) > 1:
			return i


def findDuplicate(A):
	for i in range(7):
		if A[i] == A[i + 4]:
			return A[i]


def findDuplicate(A):
	x = [d for d in A if A.count(d) == 5]
	return x[0]


def findDuplicate(A):
	for i in range(10):
		if A[i] == A[i + 1]:
			return A[i + 1]
			break


def findDuplicate(A):
	for i in range(len(A)):
		if A.count(A[i]) == 5:
			return A[i]


def findDuplicate(A):
	temp = 0
	for i in range(len(A) - 1):
		if A[i] == A[i + 1]:
			temp = A[i]
	return temp


def findDuplicate(A):
	l = []
	for i in A:
		if i not in l:
			l.append(i)
		elif i in l:
			return i


def findDuplicate(A):
	for item in A:
		if A.count(item) > 1:
			return item


def findDuplicate(A):
	i = 0
	while i <= 10:
		if A[i] == A[i + 1]:
			return A[i]
		else:
			i += 1


def findDuplicate(A):
	temp = {}
	for i in A:
		if i in temp:
			temp[i] += 1
		else:
			temp[i] = 1
	for (k, v) in temp.items():
		if v == 5:
			return k


def findDuplicate(A):
	li = []
	for i in range(len(A)):
		if A[i] not in li:
			li.append(A[i])
		else:
			break
	return A[i]


def findDuplicate(A):
	z = []
	for i in A:
		if A.count(i) > 1:
			z.append(i)
	return z[0]


def findDuplicate(A):
	l = list(A)
	for i in l:
		if l.count(i) == 5:
			return i
			break


def findDuplicate(a):
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for (key, val) in d.items():
		if val >= 5:
			return key


def findDuplicate(arr):
	if arr[4] == arr[3]:
		return arr[4]
	if arr[5] == arr[6]:
		return arr[6]


def findDuplicate(arr):
	if arr[3] == arr[4]:
		return arr[3]
	elif arr[4] == arr[5]:
		return arr[4]
	else:
		return arr[5]


from collections import Counter

def findDuplicate(A):
	d = Counter(A)
	for i in A:
		if d[i] == 5:
			return i
		else:
			pass


def findDuplicate(a):
	if a[4] == a[3]:
		return a[4]
	elif a[5] == a[6]:
		return a[5]


def findDuplicate(A):
	for i in A:
		if A.count(i) == 5:
			return i


def findDuplicate(A):
	list1 = []
	for (index, item) in enumerate(A):
		if A.count(item) == 5:
			list1.append(index)
	return A[list1[0]]


def findDuplicate(A):
	start = 0
	end = len(A) - 1
	mid = start + (end - start) // 2
	if A[start] == A[mid]:
		return A[start]
	if A[mid + 1] == A[end]:
		return A[mid + 1]
	if A[mid + 1] == A[mid]:
		return A[mid + 1]


def findDuplicate(A):
	d = set()
	for i in A:
		if i in d:
			return i
		d.add(i)


from collections import Counter

def findDuplicate(A):
	return Counter(A).most_common(1)[0][0]


from collections import Counter

def findDuplicate(A):
	cnt = Counter(A)
	num = [key for (key, val) in cnt.items() if val == 5]
	return num[0]


def findDuplicate(A):
	ans = 0
	for e in A:
		if A.count(e) == 5:
			ans = e
			break
	return ans


def findDuplicate(A):
	x = []
	for i in A:
		if i not in x:
			x.append(i)
		elif i in x:
			return i


from collections import Counter

def findDuplicate(A):
	c = Counter(A)
	l = sorted(list(c.values()), reverse=True)
	for val in A:
		if A.count(val) == l[0]:
			return val
			break


def findDuplicate(A):
	if A[0] == A[1]:
		return A[0]
	elif A[9] == A[8]:
		return A[9]
	else:
		return A[6]