Find the Runner-Up Score!

  • + 11 comments

    I think this is the best approach too to stay within O(n). My solution was something similar:

    n = int(input())
    a = [int(x) for x in input().split()]
    largest = secondlargest = -100
    for x in a:
        if x > largest:
            tmp = largest
            largest = x
            secondlargest = tmp
        elif x > secondlargest and x != largest:
            secondlargest = x
    print(secondlargest)