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 eb865a5

Browse filesBrowse files
authored
Merge pull request #13 from priyadarshan1995/master
Program to find second largest element in a list
2 parents 6fbbf90 + 5d458e0 commit eb865a5
Copy full SHA for eb865a5

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

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.