You are viewing a single comment's thread. Return to all comments →
How about the case like this: 3 5 5 5 set(nums) will only return one element, [-2] will out of index.
I mean 3 numbers: [5, 5, 5]
GO WITH THIS which does it include any sort or set func ...T.C of O(n) rather than O(logn) for sorting it
if name == 'main': n = int(input()) arr = map(int, input().split()) list1 = list(set(arr)) max=max(list1[0],list1[1]) secondmax=min(list1[0],list1[1])
for i in range(2,len(list1)): if list1[i]>max: secondmax=max max=list1[i] else: if list1[i]>secondmax: secondmax=list1[i] print(secondmax)
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
How about the case like this: 3 5 5 5 set(nums) will only return one element, [-2] will out of index.
I mean 3 numbers: [5, 5, 5]
GO WITH THIS which does it include any sort or set func ...T.C of O(n) rather than O(logn) for sorting it
if name == 'main': n = int(input()) arr = map(int, input().split()) list1 = list(set(arr)) max=max(list1[0],list1[1]) secondmax=min(list1[0],list1[1])