Skip to content

Instantly share code, notes, and snippets.

@FeezyHendrix
Last active August 19, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeezyHendrix/be896a40e1e4555e6bccd4545d6e730b to your computer and use it in GitHub Desktop.
Save FeezyHendrix/be896a40e1e4555e6bccd4545d6e730b to your computer and use it in GitHub Desktop.
Python Second Runner Up Algorithm
if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
# Convert the arr variable to a list
a = list(arr)
# a = [2, 4, 5, 2]
# Select the first item in the
# mx1 = 2
# mn = 2
mx1=a[0]
mn=a[0]
# loop through each item in list
for i in a:
# if the current item is larger than the first item replace the variable
# assume i is 2
# mx1 would be still be 2 as i is not greater than 2
# but if i is 2
# mx1 would be replaced to 4
if(i > mx1):
mx1 = i
# if the current item is less than the first item replace the varible
# if the current item is 4 and mn = 2 thus mn remain 2
if(i < mn):
mn = i
# assing mx2 to the lowest
mx2 = mn
for i in a :
if(i > mx2 and i < mx1):
mx2 = i
print(mx2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment