Skip to content

Instantly share code, notes, and snippets.

@hrubantjakub1
Last active December 17, 2020 04:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrubantjakub1/1cb20c0e8cf551a48a7c1c956c130fe5 to your computer and use it in GitHub Desktop.
Save hrubantjakub1/1cb20c0e8cf551a48a7c1c956c130fe5 to your computer and use it in GitHub Desktop.
// find element without pair in array
def solution(A):
A.sort()
for index in range(0,len(A),2):
if A[index] != A[index+1]:
return A[index]
B = [5,6,2,9,2,3,6,7,3,1,7,9,1]
print(solution(B))
@atifkarim
Copy link

Hey, I don't know whether you have modified yours or not but I have tried to modified yours and it is now giving 100% correct result according to codility

def solution(A):
A.sort()
for index in range(0,len(A),2):
boundary = len(A)-2
if index <boundary:
if A[index] != A[index+1]:
return A[index]
else:
return A[-1]

cheers !!! happy coding

@mihai011
Copy link

from collections import Counter

def solution(A):

oc  = Counter(A)
for o in oc.keys():
    if oc[o] % 2 ==1:
        return o

@educatornum
Copy link

Hey, I don't know whether you have modified yours or not but I have tried to modified yours and it is now giving 100% correct result according to codility

def solution(A):
A.sort()
for index in range(0,len(A),2):
boundary = len(A)-2
if index <boundary:
if A[index] != A[index+1]:
return A[index]
else:
return A[-1]

cheers !!! happy coding

Can you explain to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment