We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This code doesn't work for test case
5
-7 -7 -7 -7 -6
because his while he takes the input as lis the elements in it are strings not integers so you've to convert those elements into integers and then run the code.
N= input()
L= raw_input().split()
I=[]
assert N>=2 and N<=10
for i in L:
I.append(int(i))
I.sort()
largest=max(I)
count=I.count(largest)
for i in range(count):
I.remove(largest)
print max(I)
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
Oops, my bad - I missed you were using set prior sorting. Nevermind - it looks great!
5
-7 -7 -7 -7 -6
for this input i think your code wont wholes good
This code doesn't work for test case 5 -7 -7 -7 -7 -6 because his while he takes the input as lis the elements in it are strings not integers so you've to convert those elements into integers and then run the code.
N= input() L= raw_input().split() I=[] assert N>=2 and N<=10 for i in L: I.append(int(i)) I.sort() largest=max(I) count=I.count(largest) for i in range(count): I.remove(largest) print max(I)
His code works. You should try it again dude
Works in python 2 only
It still works. I just checked.
1 line.
it works.
his code would work for this input , as he is using sets concept in this , the number arent repeated in sets .
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])