Given an integer array/list(ARR) of size N. Where N is equal to [2M + 1]. Now, in the given array/list, 'M' numbers are present twice and one number is present only once. Find and return that number that is unique in the array/list.
Note: Unique element is always present in the array/list according to the given condition.
I have done this question using WHILE loop, but when I am trying to do this using FOR loop it is not working
and, I have seen some codes for this type of problem, but as I am a learner and have done only some basic python so and don't know yet about the COMPLEXITY(O^N).
please help and thanks in advance
WHILE loop code:
def find_unique(li,n):
for i in range(n):
j = 0
while(j < n):
if i != j:
if li[i] == li[j]:
break
j = j + 1
if j == n:
return li[i]
n = 7
li = [2,3,1,6,3,6,2]
ele = find_unique(li,n)
print(ele)
FOR loop code:
def find_unique(li,n):
for i in range(n):
for j in range(0,n):
if i == j:
continue
if(li[i] == li[j] and j ==n):
return li[i]
n = 7
li = [2,3,1,6,3,6,2]
ele = find_unique(li,n)
print(ele)

jever reachn?