Tasks Details
easy
1.
Dominator
Find an index of an array such that its value occurs at more than half of indices in the array.
Task Score
100%
Correctness
100%
Performance
100%
An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A.
For example, consider array A such that
A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namely in those with indices 0, 2, 4, 6 and 7) and 5 is more than a half of 8.
Write a function
def solution(A)
that, given an array A consisting of N integers, returns index of any element of array A in which the dominator of A occurs. The function should return −1 if array A does not have a dominator.
For example, given array A such that
A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3the function may return 0, 2, 4, 6 or 7, as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [0..100,000];
- each element of array A is an integer within the range [−2,147,483,648..2,147,483,647].
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 76 minutes
Notes
not defined yet
Code: 15:03:52 UTC,
java,
autosave
Code: 15:04:05 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
if len(stack) < 1:
return -1
else:
return stack.index(stack[-1])
Code: 15:04:58 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
if len(stack) < 1:
return -1
else:
return stack.index(stack[-1])
Code: 15:05:29 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
if len(stack) < 1:
return -1
else:
return stack.index(stack[-1])
Code: 15:05:33 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
if len(stack) < 1:
return -1
else:
return stack.index(stack[-1])
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.048 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.044 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
Code: 15:05:50 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
if len(stack) < 1:
return -1
else:
return stack.index(stack[-1])
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:06:28 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
Code: 15:06:44 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt +=
Code: 15:06:58 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a
Code: 15:07:09 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if
Code: 15:07:34 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]
Code: 15:07:46 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
Code: 15:08:17 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if
Code: 15:08:24 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
if len(A) == 3:
if len(set(A)) == len(A):
return -1
if len(A) == 1:
return 0
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(cnt)
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:
5
expand all
User tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0
1.
0.036 s
OK
function result: 0
function result: 0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 26, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
2
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:
1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:08:29 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(cnt)
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:
5
expand all
User tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 19, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
2
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1
1.
0.040 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
2
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:
1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:08:49 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
i
Code: 15:09:00 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >
Code: 15:44:23 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n
Code: 15:44:45 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
Example tests
1.
0.056 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
expand all
User tests
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.056 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 19, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.056 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
1.
0.052 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if cnt > n//2: NameError: name 'n' is not defined
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:44:55 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Code: 15:45:01 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.048 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[1, 1, 1, 2, 2]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:46:10 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Code: 15:46:14 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:46:55 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 15:46:56 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got -1, but dominator exists, for example on position 6
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:47:09 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:47:21 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2)
if cnt > n//2:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
0
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:47:53 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2)
if cnt > n/2:
return stack.index(stack[-1])
else:
return -1
Code: 15:47:58 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2)
if cnt > rount(n/2):
return stack.index(stack[-1])
else:
return -1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
4
expand all
User 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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
2
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 91, in main result = solution( A ) File "/tmp/solution.py", line 23, in solution if cnt > rount(n/2): NameError: name 'rount' is not definedstdout:
2
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:48:09 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2)
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
0
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:48:39 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(round(n/2))
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:48:40 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(round(n/2))
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
0
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:48:57 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(round(n/2))
print(n//2)
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
0 0
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
0 0
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1 1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2 1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2 1
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2 2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2 2
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:55:36 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:55:47 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if n % 2 == 0:
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:56:01 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if n % 2 == 0:
half
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:56:11 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if n % 2 == 0:
v =
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:56:41 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if n % 2 == 0:
threshold = n//2+1
else:
threshold = n
if cnt > round(n/2):
return stack.index(stack[-1])
else:
return -1
Code: 15:58:02 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if n % 2 == 0:
threshold = n//2+1
else:
threshold = n
if cnt > n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 15:58:07 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt > n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got -1, but dominator exists, for example on position 6
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.040 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:58:32 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2+1)
if cnt > n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got -1, but dominator exists, for example on position 6
stdout:
5
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
3
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
3
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:58:37 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2+1)
if cnt >\ n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 15:58:39 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
print(n//2+1)
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
1
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
1
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 91, in main result = solution( A ) File "/tmp/solution.py", line 20, in solution if a == stack[-1]: IndexError: list index out of range
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
2
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
2
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
3
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
3
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 15:58:50 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:01:57 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:02:01 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
print(stack)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.040 s
OK
function result: -1
function result: -1
stdout:
[]
1.
0.040 s
OK
function result: 0
function result: 0
stdout:
[0]
1.
0.040 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 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution if a == stack[-1]: IndexError: list index out of rangestdout:
[]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1, 1]
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[3]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1]
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[3]
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 16:05:26 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
print(stack)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:05:31 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
print(stack)
cnt = 0
for a in A:
if stack:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[0]
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1, 1]
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[3]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1]
1.
0.036 s
OK
function result: 0
function result: 0
stdout:
[1]
1.
0.036 s
OK
function result: -1
function result: -1
stdout:
[3]
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 16:06:00 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
print(stack)
cnt = 0
for a in A:
if a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:06:10 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
print(stack)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:06:40 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
User test case 1:
[]
User test case 2:
[0]
User test case 3:
[1, 2]
User test case 4:
[1, 1]
User test case 5:
[1, 2, 3]
User test case 6:
[1, 2, 1]
User test case 7:
[2, 1, 1, 2, 1]
User test case 8:
[1, 1, 2, 2, 3]
Code: 16:13:12 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:13:19 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
User test case 1:
[]
User test case 2:
[1, 1, 2, 2, 3]
User test case 3:
[0]
User test case 4:
[1, 2]
User test case 5:
[1, 1]
User test case 6:
[1, 2, 3]
User test case 7:
[1, 2, 1]
User test case 8:
[1, 1, 1, 2]
User test case 9:
[1, 2, 1, 2]
User test case 10:
[2, 1, 1, 2, 1]
Code: 16:14:02 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Code: 16:14:05 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return stack.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
User test case 1:
[]
User test case 2:
[1, 1, 2, 2, 3]
User test case 3:
[0]
User test case 4:
[1, 2]
User test case 5:
[1, 1]
User test case 6:
[1, 2, 3]
User test case 7:
[2, 1, 1]
User test case 8:
[1, 1, 1, 2]
User test case 9:
[1, 2, 1, 2]
User test case 10:
[2, 1, 1, 2, 1]
Code: 16:19:11 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return A.index(stack[-1])
else:
return -1
Code: 16:19:12 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return A.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 1
function result: 1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 1
function result: 1
User test case 1:
[]
User test case 2:
[1, 1, 2, 2, 3]
User test case 3:
[0]
User test case 4:
[1, 2]
User test case 5:
[1, 1]
User test case 6:
[1, 2, 3]
User test case 7:
[2, 1, 1]
User test case 8:
[1, 1, 1, 2]
User test case 9:
[1, 2, 1, 2]
User test case 10:
[2, 1, 1, 2, 1]
Code: 16:19:37 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return A.index(stack[-1])
else:
return -1
Analysis
expand all
User tests
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 1
function result: 1
1.
0.036 s
OK
function result: 0
function result: 0
1.
0.036 s
OK
function result: -1
function result: -1
1.
0.036 s
OK
function result: 1
function result: 1
User test case 1:
[]
User test case 2:
[1, 1, 2, 2, 3]
User test case 3:
[0]
User test case 4:
[1, 2]
User test case 5:
[1, 1]
User test case 6:
[1, 2, 3]
User test case 7:
[2, 1, 1]
User test case 8:
[1, 1, 1, 2]
User test case 9:
[1, 2, 1, 2]
User test case 10:
[2, 1, 1, 2, 1]
Code: 16:19:41 UTC,
py,
final,
score: 
100
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
n = len(A)
stack = []
for a in A:
if not stack:
stack.append(a)
else:
if stack[-1] != a:
stack.pop()
else:
stack.append(a)
cnt = 0
for a in A:
if stack and a == stack[-1]:
cnt += 1
if cnt >= n//2+1:
return A.index(stack[-1])
else:
return -1
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N*log(N)) or O(N)
expand all
Correctness tests
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
1.
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
1.
0.036 s
OK
2.
0.036 s
OK