human
Unique element in an array where all elements occur K times except one | Set 2 | Function to find single occurrence element.
By shifting 1 to left ith time and taking and with 1 will give us that ith bit of a [ j ] is 1 or 0.
Taking modulo of p with k.
Generate result.
Loop for negative numbers.
Check if the calculated value res is present in array , then mark c = 1 and if c = 1 return res else res must be - ve.
Driver code.
Function call"
Solution in Python:
assistant
#Here is code to unique element in an array where all elements occur K times except one and the other steps required.
 def findunique ( a , k ) :
	res = 0
	for i in range ( 32 ) :
		p = 0
		for j in range ( len ( a ) ) :
			if ( abs ( a [ j ] ) & ( 1 << i ) ) != 0 :
				p += 1
		p %= k
		res += pow ( 2 , i ) * p
	c = 0
	for x in a :
		if ( x == res ) :
			c = 1
			break
	if c == 1 :
		return res
	else :
		return - res
a = [ 12 , 12 , 2 , 2 , 3 ]
k = 2
print ( findunique ( a , k ) )