Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d458e0

Browse filesBrowse files
author
Priyadarshan Mohanty
committed
Program to find second largest element in list
1 parent e97c0c7 commit 5d458e0
Copy full SHA for 5d458e0

File tree

1 file changed

+18
-0
lines changed
Filter options

1 file changed

+18
-0
lines changed

‎second-largest-num.py

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Program to find second largest element in list
2+
# Time Complexity : O(N)
3+
# run cmd: python3 second-largest-num.py
4+
5+
class Solution:
6+
def secondLargest(self, l):
7+
mx=max(l[0],l[1])
8+
secondmx=min(l[0],l[1])
9+
n =len(l)
10+
for i in range(2,n):
11+
if l[i]>mx:
12+
secondmx=mx
13+
mx=l[i]
14+
elif l[i]>secondmx and mx != l[i]:
15+
secondmx=l[i]
16+
return secondmx
17+
18+
print("Second Largest number is :", Solution().secondLargest([12,412,11,42,10,1]))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.