Dominator 100% Solution in python

Question

app.codility.com

My Solution

app.codility.com

def solution(A):
    
    stack = [0]*len(A)
    size = 0
    index = -1
    count = 0
    
    for i in range(len(A)):
        if size == 0:
            stack[size] = A[i]
            size += 1
        else: 
            if stack[size-1] != A[i]:
                size -= 1
            else:
                stack[size] = A[i]
                size += 1
    
    # now dominents are remained in the stack
    for i in range(len(A)):
        if A[i] == stack[size-1]:
            index = i
            count += 1
    
    if count > len(A)/2:
        return index
    else:
        return -1

Note

codility.com is worth reading!