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 a[] of n integers each separated by a space
n = int(input())
a = [int(x) for x in input().split()]
bestScore = a[0]
for score in a:
if score > bestScore:
bestScore = score
isRunnerUpDefined = False
runnerUpScore = -1
for score in a:
if score != bestScore and (not isRunnerUpDefined or score > runnerUpScore):
runnerUpScore = score
isRunnerUpDefined = True
if isRunnerUpDefined:
print(runnerUpScore)
else:
print("There is no runner up")
Comments
Leave a comment