Answer to Question #235933 in Python for akshita

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
1
Expert's answer
2021-09-11T07:01:34-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS