2 <= n <= 10 -100 <= A[i] <= 100
python problem 1: find the runner-up score
Carvia Tech | December 07, 2019 | 1 min read | 9,216 views
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.
This is in reference to Python 3
The first line contains n. The second line contains an array A of n integers each separated by a space.
Print the runner-up score.
5 2 3 6 6 5
We are going to keep logic in main function only such that we are able to build array as we will be getting data from input.
You shall create a
script.py file and paste the below code in it.
n = int(input()) This takes input from command line. Please note that input type is going to be in string
format and we have to use
int() to convert from
arr = map(int, input().split()) Now, we are are mapping input(text) to int.
arr = list(set(list(arr))) here we are convert array to list and getting its set and then converting to list.
Others: We are sorting the list by using
sorted and getting second last element.
if __name__=="__main__": n = int(input()) arr = map(int, input().split()) arr = list(set(list(arr))) ar = len(arr) arr = sorted(arr) print(arr[ar-2])
Top articles in this category:
- Python coding challenges for interviews
- Python Flask Interview Questions
- Top 100 interview questions on Data Science & Machine Learning
- Google Data Scientist interview questions with answers
- Find extra long factorials in python
- Write a program for Hailstone Sequence in Python
- Pass the ball game: NxN matrix in python
Find more on this topic:
Data science, machine learning, python, R, big data, spark, the Jupyter notebook, and much more
Last updated 1 week ago
Recommended books for interview preparation:
- Configure Logging in gunicorn based application in docker container
- Connect to Cassandra with Python 3.x and get Pandas Dataframe
- Connect to MySQL with Python 3.x and get Pandas Dataframe
- Connect to Postgresql with Python 3.x and get Pandas Dataframe
- Python - Get Google Analytics Data
- Installing PySpark with Jupyter notebook on Ubuntu 18.04 LTS
- Python send GMAIL with attachment
- Send rich text multimedia email in Python
- Blueprints in Flask API Development
- Singleton Design Pattern in Python