Find The Runner-Up Score!
Task
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given n scores. Store them in a list and find the score of the runner-up.
Solution:
if __name__=="__main__": n = int(input()) arr = map(int, input().split()) arr = list(set(list(arr))) ar = len(arr) arr = sorted(arr) print(arr[ar-2]) |
Note:
This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.
Disclaimer:-
The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.
Find the Runner-Up Score! - Hackerrank solution
Reviewed by CodexRitik
on
March 15, 2020
Rating:
can u explain the code pls, hlps a lot
ReplyDeleteIn this Ques You Have to find second maximum in given scores ,therefore i have first created a list of scores then using set we have got list of unique elements and also finded a length of list then for second one use len - 2.you can also find using loop method.
Deleten = int(input())
ReplyDeletearr = input().split()
s = sorted(arr)
i = n
while i != 0:
if s[i-1] != s[n-1]:
print(s[i-1])
break
i -= 1