You are viewing a single comment's thread. Return to all 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)
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
I think this is the best approach too to stay within O(n). My solution was something similar: