Skip to content

Instantly share code, notes, and snippets.

@ranasaani
Created May 9, 2019 16:50
Show Gist options
  • Save ranasaani/fb8ced4a78b3eb3c3b57784798f06670 to your computer and use it in GitHub Desktop.
Save ranasaani/fb8ced4a78b3eb3c3b57784798f06670 to your computer and use it in GitHub Desktop.
Find the second minimum element of an array
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