Given the participants' score sheet for your University Sports
Day, you are required to find the runner-up score. You are given n 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 integers each
separated by a space.
Constraints
·
2<=n<=10
·
-100 <=A[i]<=100
Output Format
Print the runner-up
score.
Sample Input 0
5
2 3 6 6 5
Sample Output 0
5
Explanation 0
Given list is [2,3,6,6,5].
The maximum score is 6, second
maximum is 5 . Hence, we
print 5 as the runner-up
score.
Solution:-
Problem solution in Python 2 programming.
# Enter your code here. Read input from STDIN. Print output to STDOUT
def max(l):
return sorted(set(l))[-2]
test = int(raw_input())
l = [int(_) for _ in raw_input().split()]
print max(l)
Problem solution in Python 3 programming.
if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
arr = list(arr)
x = max(arr)
y = -9999999
for i in range(0,n):
if arr[i]<x and arr[i] > y:
y = arr[i]
print(y)
Problem solution in pypy programming.
if __name__ == '__main__':
n = int(raw_input())
arr = map(int, raw_input().split())
Max = max(arr)
while max(arr) == Max:
arr.remove(max(arr))
print max(arr)
Problem solution in pypy3 programming.
if __name__ == '__main__':
n = int(input())
#print (input().split())
#arr = [int(x) for x in input().split()]
#print (list(input()))
arr = list(map(int, input().split()))
#print (arr)
#arr = sorted(arr)
arr.sort()
#print (arr)
for i in range(n-1, -1, -1):
if arr[i]<arr[n-1]:
temp = arr[i]
break
print (temp)
#sorted(arr)
#print (arr[n-1])
0 Comments