Tasks Details
easy
Find value that occurs in odd number of elements.
Task Score
66%
Correctness
100%
Performance
25%
A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.
For example, in array A such that:
A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9
- the elements at indexes 0 and 2 have value 9,
- the elements at indexes 1 and 3 have value 3,
- the elements at indexes 4 and 6 have value 9,
- the element at index 5 has value 7 and is unpaired.
Write a function:
def solution(A)
that, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.
For example, given array A such that:
A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9the function should return 7, as explained in the example above.
Write an efficient algorithm for the following assumptions:
- N is an odd integer within the range [1..1,000,000];
- each element of array A is an integer within the range [1..1,000,000,000];
- all but one of the values in A occur an even number of times.
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 7 minutes
Notes
not defined yet
Task timeline
Code: 15:05:02 UTC,
java,
autosave
Code: 15:07:15 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.040 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[9, 3, 9, 3, 9, 7, 9]
Code: 15:09:09 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.040 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[9, 3, 9, 3, 9, 7, 9] [0, 0, 0, 0, 0, 0, 0]
Code: 15:11:17 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[9, 3, 9, 3, 9, 7, 9] 7
Code: 15:11:28 UTC,
py,
verify,
result: Passed
Analysis
Code: 15:11:42 UTC,
py,
verify,
result: Passed
Analysis
Code: 15:11:44 UTC,
py,
final,
score: 
66
Analysis summary
The following issues have been detected: timeout errors.
Analysis
Detected time complexity:
O(N**2)
expand all
Performance tests
1.
0.040 s
OK
1.
6.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 6.000 sec.
big1
big random test n=999,999, multiple repetitions
big random test n=999,999, multiple repetitions
✘
TIMEOUT ERROR
Killed. Hard limit reached: 10.000 sec.
Killed. Hard limit reached: 10.000 sec.
1.
10.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 10.000 sec.
1.
10.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 10.000 sec.