2 <= n <= 10 -100 <= A[i] <= 100
python problem 1: find the runner-up score
Carvia Tech | December 07, 2019 | 1 min read | 16,604 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
- Find extra long factorials in python
- Write a python program to find Largest Substring that occurs more than once
- Write a program for Hailstone Sequence in Python
- Derivative of 1/x & Tossing a coin problem
- Pass the ball game: NxN matrix in python
- Write a program to check if the given word is Isogram & Pair isogram in python