Created
May 9, 2019 16:50
-
-
Save ranasaani/fb8ced4a78b3eb3c3b57784798f06670 to your computer and use it in GitHub Desktop.
Find the second minimum element of an array
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
def second_minimum(arr): | |
second = arr[1] | |
first = arr[0] | |
for n in arr: | |
if n < first: | |
first = n | |
if n < second and n > first: | |
second = n | |
return second | |
second_minimum([-2, 4, 5, -1, 2, 3, 0, -4, 1, 99, -6, -5, -19]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment