Menu Close

Every element in array appears twice.Find that single one.

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Input : Array = [7,1,2,3,1,2,3]
Output : 7
#use for loop if necessary
Arr = list(map(int,input('Enter the array elements : ').split(' ')))
temp=0
for i in range(len(Arr)):
	temp=temp^Arr[i]   # using Xor operator

print('Minimum - ',temp)

Input_1:
Enter the array elements : 1 2 3 7 1 2 3
Output:
Minimum – 7


Input_2:
Enter the array elements : 7 8 9 6 7 8 9
Output:
Minimum – 6


Input_3:
Enter the array elements : 20 25 30 20 30
Output:
Minimum – 25


Input_4:
Enter the array elements : 9 6 3 2 9 3 6
Output:
Minimum – 2


Input_5:
Enter the array elements : 7 4 1 2 2 4 7
Output:
Minimum – 1


ILLUSTRATION OF THE OUTPUT

Executed using python3 terminal(linux)

More Q