forked from minaevd/hackerrank-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecondMax.py
More file actions
executable file
·41 lines (32 loc) · 777 Bytes
/
Copy pathsecondMax.py
File metadata and controls
executable file
·41 lines (32 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Task: Find the Second Largest Number
URL: https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list
Description: You are given N numbers. Store them in a list and find the second largest number.
"""
cnt = raw_input()
mylist = map(int, raw_input().split())
max1 = mylist[0]
max2 = None
# O(N log N)
############
# sorted_myset = sorted(myset)
# print sorted_myset[len(sorted_myset)-2]
# O(N)
######
#for i in (myset):
# if i>max1:
# max1=i
#
#for i in (myset):
# if (max2 == None or i>max2) and i<max1:
# max2=i
#print max2
# O(N) but one cycle walk only
##############################
for i in (mylist):
if(max2 == None or i > max2) and i < max1:
max2 = i
if(i>max1):
max2=max1
max1=i
print max2