Last active
August 19, 2020 13:32
-
-
Save FeezyHendrix/be896a40e1e4555e6bccd4545d6e730b to your computer and use it in GitHub Desktop.
Python Second Runner Up Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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