Skip to content

Instantly share code, notes, and snippets.

@danielchikaka
Created April 20, 2022 08:18
Show Gist options
  • Save danielchikaka/e68713a2a0d7357e0f8cf8ff60bcd637 to your computer and use it in GitHub Desktop.
Save danielchikaka/e68713a2a0d7357e0f8cf8ff60bcd637 to your computer and use it in GitHub Desktop.
Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, return an empty array/list. Don't change the order of the elements that are left.
# def remove_smallest(numbers):
# arr = numbers[:]
# if len(arr) > 0:
# arr.pop(arr.index(min(arr)))
# return arr
# else:
# return []
def remove_smallest(numbers):
a = numbers[:]
if a:
a.remove(min(a))
return a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment