Tasks Details
easy
Find a symmetry point of a string, if any.
Task Score
100%
Correctness
100%
Performance
100%
Write a function:
def solution(S)
that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return −1 if no such index exists.
Note: reversing an empty string (i.e. a string whose length is zero) gives an empty string.
For example, given a string:
"racecar"
the function should return 3, because the substring to the left of the character "e" at index 3 is "rac", and the one to the right is "car".
Given a string:
"x"
the function should return 0, because both substrings are empty.
Write an efficient algorithm for the following assumptions:
- the length of string S is within the range [0..2,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 9 minutes
Notes
not defined yet
Task timeline
Code: 15:07:48 UTC,
java,
autosave
Code: 15:08:05 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.
1.
0.036 s
WRONG ANSWER,
got -1 expected 0
Code: 15:08:32 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got -1 expected 3
1.
0.036 s
WRONG ANSWER,
got -1 expected 0
Code: 15:09:05 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:
3
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0
Code: 15:16:08 UTC,
py,
autosave
Code: 15:16:20 UTC,
py,
verify,
result: Passed
Analysis
Code: 15:16:25 UTC,
py,
verify,
result: Passed
Analysis
Code: 15:16:28 UTC,
py,
final,
score: 
100
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(length(S))
expand all
Correctness tests
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
2.
0.036 s
OK
3.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
3.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
1.
0.036 s
OK
1.
0.036 s
OK
2.
0.044 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
expand all
Performance tests
1.
0.044 s
OK
2.
0.036 s
OK
3.
0.036 s
OK
1.
0.044 s
OK
1.
0.052 s
OK
1.
0.120 s
OK
1.
0.120 s
OK
2.
0.040 s
OK
3.
0.036 s
OK
1.
0.200 s
OK
2.
0.040 s
OK
3.
0.204 s
OK
4.
0.040 s
OK
5.
0.040 s
OK
6.
0.200 s
OK