Tasks Details
easy
Find the missing element in a given permutation.
Task Score
90%
Correctness
80%
Performance
100%
An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.
Your goal is to find that missing element.
Write a function:
def solution(A)
that, given an array A, returns the value of the missing element.
For example, given array A such that:
A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5the function should return 4, as it is the missing element.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [0..100,000];
- the elements of A are all distinct;
- each element of array A is an integer within the range [1..(N + 1)].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Total time used 2 minutes
Effective time used 2 minutes
Notes
not defined yet
Task timeline
Code: 08:01:43 UTC,
java,
autosave
Code: 08:02:08 UTC,
py,
autosave
Code: 08:02:34 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 70, in main sol = __import__('solution') File "/tmp/solution.py", line 13 print(dict_) ^ IndentationError: unindent does not match any outer indentation level
Code: 08:02:39 UTC,
py,
autosave
Code: 08:02:40 UTC,
py,
verify,
result: Passed
Analysis
expand all
Example tests
1.
0.036 s
OK
stdout:
{1: 0, 2: 0, 3: 0, 4: 0} {1: 1, 2: 1, 3: 1, 4: 0, 5: 1}
Code: 08:03:11 UTC,
py,
autosave
Code: 08:03:14 UTC,
py,
verify,
result: Passed
Analysis
expand all
Example tests
1.
0.036 s
OK
stdout:
{1: 0, 2: 0, 3: 0, 4: 0, 5: 0} {1: 1, 2: 1, 3: 1, 4: 0, 5: 1}
Code: 08:03:26 UTC,
py,
verify,
result: Passed
Analysis
Code: 08:03:29 UTC,
py,
final,
score: 
90
Analysis summary
The following issues have been detected: runtime errors.
For example, for the input [] the solution terminated unexpectedly.
Analysis
Detected time complexity:
O(N) or O(N * log(N))
expand all
Correctness tests
empty_and_single
empty list and single element
empty list and single element
✘
RUNTIME ERROR
tested program terminated with exit code 1
tested program terminated with exit code 1
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.
2.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
3.
0.036 s
OK
1.
0.036 s
OK
expand all
Performance tests
1.
0.048 s
OK
1.
0.048 s
OK
1.
0.160 s
OK
2.
0.096 s
OK
3.
0.100 s
OK
1.
0.168 s
OK
1.
0.108 s
OK