My code has complexity of O(n) but says Failing for large test cases. Any help?


#1
from  collections import Counter

class Solution:
    # @param A : list of integers
    # @return an integer
    def perfectPeak(self, A):
        # All elements are equal
        if len(Counter(A)) == 1:
            return 0
        
        # Duplicate elements
        for i in range(len(A) - 1):
            if A[i] == A[i+1]:
                return 0
            
        max_list = [A[0]]
        min_list = [A[-1]]
        res = []
        
        for i in range(1, len(A)-1):
            max_list.append(max(max_list[-1], A[i]))
            min_list.append(min(min_list[-1], A[len(A) - i - 1]))
        
        intersection = set(max_list) & set(min_list)
        
        if len(intersection) > 0:
            return 1
        
        
        return 0