+ 2
Find the runner up score , help me in finding the mistake ...
# Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up. # Input Format # The first line contains n . The second line contains an array of n integers each separated by a space. # Output Format # Print the runner-up score. # Sample Input # 5 # 2 3 6 6 5 # Sample Output # 5 Here is my solution đđđ n = int(input()) a = input().split() # print(max(a)) m = a[0] for i in a: if m<i: m = i # finding the largest number m_1 = a[0] # print(m) for i in a: if m_1<i and i<m: m_1 = i # finding the 2nd largest number print(m_1)
12 Respostas
+ 3
The way I would have done it
a="2 3 3 4 6 6 5"
b=a.split()
c=max(b)
while c in b:
b.remove(c)
print(b)
print(max(b))
I am trying to understand your solution tho
your solution outputs right result if I am not wrong ,so i don't really understand what is the problem!
Also I think the constraints in this solution would be no use of max? otherwise using max you can find it easily
+ 3
Pls add a link of your hackerrank problm.
+ 2
Well you can easily add inputs in here ,
n=input()
a=input()
+ 2
yes
+ 2
can you show what you are trying to do ? because I don't believe it will give runtime error
+ 2
https://code.sololearn.com/cy5B2DigM43G/?ref=app
Here its working properly bt the same code when i am submitting on hackerrank platform its giving run time error
+ 2
C,Cpp,Java,Html.
đđąđąđđš đđĄđđČđđ„
https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem
there are some questions I have solved here on hackerrank bt while compiling it's giving me sometimes compilation error, syntax error and sometimes runtime error but I am not getting anyone of this error.
+ 1
Abhay here we have to take two inputs bt u have not used input ?why
+ 1
We can also wirte it as
a = input().split()
....?
+ 1
Bt when we are giving input in program. Its giving runtime errorđ
+ 1
đđąđąđđš đđĄđđČđđ„ which link ?