Tasks Details
easy
1.
EquiLeader
Find the index S such that the leaders of the sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N - 1] are the same.
Task Score
55%
Correctness
100%
Performance
0%
A non-empty array A consisting of N integers is given.
The leader of this array is the value that occurs in more than half of the elements of A.
An equi leader is an index S such that 0 ≤ S < N − 1 and two sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N − 1] have leaders of the same value.
For example, given array A such that:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2we can find two equi leaders:
- 0, because sequences: (4) and (3, 4, 4, 4, 2) have the same leader, whose value is 4.
- 2, because sequences: (4, 3, 4) and (4, 4, 2) have the same leader, whose value is 4.
The goal is to count the number of equi leaders.
Write a function:
def solution(A)
that, given a non-empty array A consisting of N integers, returns the number of equi leaders.
For example, given:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2the function should return 2, as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000,000..1,000,000,000].
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 42 minutes
Notes
not defined yet
Task timeline
Code: 09:51:07 UTC,
java,
autosave
Code: 09:53:22 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:
0 4 1 3 2 4 3 4 4 4 5 2
Code: 09:56:02 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 10 ^ SyntaxError: unexpected EOF while parsing
Code: 09:56:11 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 10 ^ SyntaxError: unexpected EOF while parsing
Code: 09:56:21 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, 4, 4, 4, 2] [4] [4, 4, 4, 2] [4, 3] [4, 4, 2] [4, 3, 4] [4, 2] [4, 3, 4, 4] [2] [4, 3, 4, 4, 4] [] [4, 3, 4, 4, 4, 2]
Code: 09:57:08 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, 4, 4, 4, 2] [4] [4, 4, 4, 2] [4, 3] [4, 4, 2] [4, 3, 4] [4, 2] [4, 3, 4, 4] [2] [4, 3, 4, 4, 4]
Code: 09:57:26 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:
[4] [3, 4, 4, 4, 2] [4, 3] [4, 4, 4, 2] [4, 3, 4] [4, 4, 2] [4, 3, 4, 4] [4, 2] [4, 3, 4, 4, 4] [2]
Code: 10:03:11 UTC,
py,
autosave
Code: 10:03:21 UTC,
py,
autosave
Code: 10:03:39 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:
4 3 4 4 4 2 4 3 4 4 4 2 4 3 4 4 4 2 4 3 4 4 4 2 4 3 4 4 4 2
Code: 10:04:16 UTC,
py,
autosave
Code: 10:05:57 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
for i, _ in enumerate(A[:-1:]):
for num in A[:i+1]:
count = collections.defaultdict(int)
count[num] += 1
print("count :::" + str(count))
for num in A[i+1:]:
print(num)
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:
count :::defaultdict(<class 'int'>, {4: 1}) 3 4 4 4 2 count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {3: 1}) 4 4 4 2 count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {3: 1}) count :::defaultdict(<class 'int'>, {4: 1}) 4 4 2 count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {3: 1}) count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {4: 1}) 4 2 count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {3: 1}) count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {4: 1}) count :::defaultdict(<class 'int'>, {4: 1}) 2
Code: 10:06:19 UTC,
py,
autosave
Code: 10:06:30 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
for i, _ in enumerate(A[:-1:]):
count = collections.defaultdict(int)
for num in A[:i+1]:
count[num] += 1
print("count :::" + str(count))
for num in A[i+1:]:
print(num)
Code: 10:06:44 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("count :::" + str(count))
for num in A[i+1:]:
print(num)
Code: 10:07:01 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print(count_first)
for num in A[i+1:]:
print(num)
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:
defaultdict(<class 'int'>, {4: 1}) 3 4 4 4 2 defaultdict(<class 'int'>, {4: 1, 3: 1}) 4 4 4 2 defaultdict(<class 'int'>, {4: 2, 3: 1}) 4 4 2 defaultdict(<class 'int'>, {4: 3, 3: 1}) 4 2 defaultdict(<class 'int'>, {4: 4, 3: 1}) 2
Code: 10:07:17 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:07:28 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
A_lenght = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:07:41 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
A_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
A
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:07:57 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print(a_length - i)
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:09:58 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:10:15 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print((i + 1))
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:10:25 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("" + str(i + 1))
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:10:36 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("first_num ::: " + str(i + 1))
print(count_first)
for num in A[i+1:]:
print(num)
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:
first_num ::: 1 defaultdict(<class 'int'>, {4: 1}) 3 4 4 4 2 first_num ::: 2 defaultdict(<class 'int'>, {4: 1, 3: 1}) 4 4 4 2 first_num ::: 3 defaultdict(<class 'int'>, {4: 2, 3: 1}) 4 4 2 first_num ::: 4 defaultdict(<class 'int'>, {4: 3, 3: 1}) 4 2 first_num ::: 5 defaultdict(<class 'int'>, {4: 4, 3: 1}) 2
Code: 10:10:52 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("first_num ::: " + str(i + 1))
print(count_first)
for
for num in A[i+1:]:
print(num)
Code: 10:11:05 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("first_num ::: " + str(i + 1))
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:11:23 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("first_num ::: " + str(i + 1))
print(count_first)
first_true
for num in A[i+1:]:
print(num)
Code: 10:11:33 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
for i, _ in enumerate(A[:-1:]):
count_first = collections.defaultdict(int)
for num in A[:i+1]:
count_first[num] += 1
print("first_num ::: " + str(i + 1))
print(count_first)
for num in A[i+1:]:
print(num)
Code: 10:17:48 UTC,
py,
autosave
Code: 10:17:58 UTC,
py,
autosave
Code: 10:18:22 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
Code: 10:18:52 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
Code: 10:19:12 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
count(lead_num, )
Code: 10:19:27 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
count(lead_num, )
Code: 10:20:10 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
count(lead_num, 3)
Code: 10:20:21 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
count(lead_num)
Code: 10:20:35 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print(A[i+1:].count(lead_num))
Code: 10:20:50 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print(A[:].count(lead_num))
print(A[:])
Code: 10:21:03 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print(A[:i + 1].count(lead_num))
print(A[i + 1:].count(lead_num))
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:
1 3 1 3 2 2 3 1 4 0 4 0
Code: 10:21:12 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print(A[:i + 1].count(lead_num))
print(A[i + 1:].count(lead_num))
Code: 10:21:23 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) >
print(A[i + 1:].count(lead_num))
Code: 10:21:39 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and print(A[i + 1:].count(lead_num))
Code: 10:21:50 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num)
Code: 10:23:04 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num)
Code: 10:23:20 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) a_length - i
Code: 10:23:34 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
Code: 10:23:44 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
Code: 10:24:14 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer
Code: 10:24:22 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer += 1
return answer
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got 1 expected 2
Code: 10:24:48 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:]):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer += 1
return answer
Code: 10:25:01 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer += 1
return answer
Analysis
expand all
Example tests
1.
0.040 s
WRONG ANSWER,
got 1 expected 2
Code: 10:25:18 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print()
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Code: 10:25:34 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A):
print(A[:i+1])
print(A[i+1:])
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got 0 expected 2
stdout:
[4] [3, 4, 4, 4, 2] [4, 3] [4, 4, 4, 2] [4, 3, 4] [4, 4, 2] [4, 3, 4, 4] [4, 2] [4, 3, 4, 4, 4] [2] [4, 3, 4, 4, 4, 2] []
Code: 10:25:49 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[::=]):
print(A[:i+1])
print(A[i+1:])
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Code: 10:25:53 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[::-1]):
print(A[:i+1])
print(A[i+1:])
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got 0 expected 2
stdout:
[4] [3, 4, 4, 4, 2] [4, 3] [4, 4, 4, 2] [4, 3, 4] [4, 4, 2] [4, 3, 4, 4] [4, 2] [4, 3, 4, 4, 4] [2] [4, 3, 4, 4, 4, 2] []
Code: 10:26:03 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print(A[:i+1])
print(A[i+1:])
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got 0 expected 2
stdout:
[4] [3, 4, 4, 4, 2] [4, 3] [4, 4, 4, 2] [4, 3, 4] [4, 4, 2] [4, 3, 4, 4] [4, 2] [4, 3, 4, 4, 4] [2]
Code: 10:26:32 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
#print(A[:i+1])
print(A[i+1:])
#if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
#answer += 1
return answer
Code: 10:26:38 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
#print(A[:i+1])
#print(A[i+1:])
if A[:i + 1].count(lead_num) > i / 2 and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer += 1
return answer
Analysis
expand all
Example tests
1.
0.036 s
WRONG ANSWER,
got 1 expected 2
Code: 10:27:32 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
#print(A[:i+1])
#print(A[i+1:])
if A[:i + 1].count(lead_num) > i / 2
and A[i + 1:].count(lead_num) > (a_length - i)/2:
answer += 1
return answer
Code: 10:27:43 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
#print(A[:i+1])
#print(A[i+1:])
if A[:i + 1].count(lead_num) > i / 2
and A[i + 1:].count(lead_num)
return answer
Code: 10:28:07 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
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:
1 3 1 3 2 2 3 1 4 0
Code: 10:28:29 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
Code: 10:28:40 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print(i)
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
Code: 10:28:51 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print(i + 1)
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
Code: 10:29:10 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
Code: 10:29:15 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
print(A[:i + 1].count(lead_num))
print( A[i + 1:].count(lead_num))
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:
0.5 1 3 1.0 1 3 1.5 2 2 2.0 3 1 2.5 4 0
Code: 10:29:40 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
print(A[:i + 1].count(lead_num))
print((a_length - i))
print( A[i + 1:].count(lead_num))
Code: 10:29:55 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
print(A[:i + 1].count(lead_num))
print((a_length - i - 1))
print( A[i + 1:].count(lead_num))
Code: 10:30:07 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
print(A[:i + 1].count(lead_num))
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
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:
0.5 1 2.5 3 1.0 1 2.0 3 1.5 2 1.5 2 2.0 3 1.0 1 2.5 4 0.5 0
Code: 10:30:23 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
print(A[:i + 1].count(lead_num))
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
if A[:i+1]
Code: 10:30:37 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) >
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
Code: 10:30:50 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) > (i+1) / 2 and
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
Code: 10:31:01 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num)
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
Code: 10:31:18 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > a_length -
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
Code: 10:31:36 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
print((a_length - i - 1)/2)
print( A[i + 1:].count(lead_num))
Code: 10:31:47 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
print((i + 1)/2)
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
Code: 10:31:57 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
print(answer)
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:
2
Code: 10:32:07 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
return answer
Analysis
Code: 10:32:13 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
return answer
Analysis
Code: 10:32:16 UTC,
py,
final,
score: 
55
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(A):
a_length = len(A)
a_hash = collections.defaultdict(int)
lead_num = 0
answer=0
for i, num in enumerate(A):
a_hash[num] += 1
if a_hash[num] > a_length/2:
lead_num = num
break
for i , _ in enumerate(A[:-1]):
if A[:i + 1].count(lead_num) > (i+1) / 2 and A[i+1 : ].count(lead_num) > (a_length - i - 1) / 2:
answer += 1
return answer
Analysis summary
The following issues have been detected: timeout errors.
Analysis
Detected time complexity:
O(N ** 2)
expand all
Correctness tests
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
expand all
Performance tests
large_random
large random test with two values, length = ~50,000
large random test with two values, length = ~50,000
✘
TIMEOUT ERROR
Killed. Hard limit reached: 6.000 sec.
Killed. Hard limit reached: 6.000 sec.
1.
6.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 6.000 sec.
large
random(0,1) + 50000 * [0] + random(0, 1), length = ~100,000
random(0,1) + 50000 * [0] + random(0, 1), length = ~100,000
✘
TIMEOUT ERROR
Killed. Hard limit reached: 6.000 sec.
Killed. Hard limit reached: 6.000 sec.
1.
6.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 6.000 sec.
large_range
1, 2, ..., N, length = ~100,000
1, 2, ..., N, length = ~100,000
✘
TIMEOUT ERROR
Killed. Hard limit reached: 6.000 sec.
Killed. Hard limit reached: 6.000 sec.
1.
6.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 6.000 sec.
2.
0.036 s
OK
1.
6.000 s
TIMEOUT ERROR,
Killed. Hard limit reached: 6.000 sec.