Suppose we have a list of scores for different number of participants. We have to find the runner-up score.
So, if the input is like scores = [5,8,2,6,8,5,8,7], then the output will be 7 because the winner score is 8 and second largest score is 7.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding
def solve(scores): winner = -99999 runner_up = -99999 for i in scores: if (i > winner): winner, runner_up = i, winner elif (i < winner and i > runner_up): runner_up = i return runner_up scores = [5,8,2,6,8,5,8,7] print(solve(scores))