Question #235933

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

Expert's answer

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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS