Friday, December 16, 2016

Find the Second Largest Number

You are given numbers. Store them in a list and find the second largest number.

Input Format
The first line contains . The second line contains an array [] of integers each separated by a space.
Output Format
Output the value of the second largest number.
Sample Input
5
2 3 6 6 5
Sample Output
5
 
Python 3.0 code:
 
limit=int(input())
x=0
inputv=[]
inputv=input()
splittedinput=inputv.split()
splittedinput=list(set(splittedinput))
#print(splittedinput)
sortedinput=sorted(splittedinput,key=int)
#print(sortedinput.values())
#print(len(sortedinput))
print(sortedinput[len(sortedinput)-2])