Find the Runner-Up Score!

  • + 0 comments

    Isn't it calculating max in the list two times with complexity O(n) + O(n). It is possible to do it in one loop ..

    if __name__ == '__main__':
        n = int(input())
        arr = list(map(int, input().split()))
        
        max =  arr[0]
        runner = -9999
        for score in arr[1:]:
            if score > max:
                runner = max
                max = score
            elif score < max and score > runner:
                runner = score
        print(runner)