- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find runner-up score
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 −
- winner := -99999
- runner_up := -99999
- for each i in scores, do
- if i > winner, then
- winner := i
- runner_up := winner
- otherwise when i < winner and i > runner_up, then
- runner_up := i
- if i > winner, then
- return runner_up
Example
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))
Input
[5,8,2,6,8,5,8,7]
Output
7
- Related Articles
- Program to find maximum score from removing stones in Python
- Program to find maximum score in stone game in Python
- Program to find maximize score after n operations in Python
- Python program to find word score from list of words
- Program to find maximum additive score by deleting numbers in Python
- Program to find maximum score from performing multiplication operations in Python
- Program to find minimum difference of stone games score in Python
- Program to find maximum score of a good subarray in Python
- Program to find maximum score of brick removal game in Python
- Python program to find score and name of winner of minion game
- Program to find the maximum score from all possible valid paths in Python
- Program to find maximum score we can get in jump game in Python
- Python program to find average score of each students from dictionary of scores
- Program to find maximum score by splitting binary strings into two parts in Python
- Program to find Fibonacci series results up to nth term in Python

Advertisements