Description:
The museum of incredible dull things
The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the one with the lowest rating.
However, just as she finished rating all exhibitions, she's off to an important fair, so she asks you to write a program that tells her the ratings of the items after one removed the lowest one. Fair enough.
Task
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.
Examples
* Input: [1,2,3,4,5], output= [2,3,4,5]
* Input: [5,3,2,1,4], output = [5,3,2,4]
* Input: [2,2,1,2,1], output = [2,2,2,1]
Solution:
1. If the input array is an empty array, it is returned as is.
2. Copy the original array.
3. Returns an array after subtracting the minimum value from the copied array.
def remove_smallest(numbers):
arr = numbers[:]
return numbers and arr.pop(arr.index(min(arr))) and arr
The problem is that the original array should not be changed, so you have to copy the input array and use it.
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Vowel Count (0) | 2022.04.22 |
---|---|
String ends with? (0) | 2022.04.21 |
Sum of two lowest positive integers (0) | 2022.04.19 |
Square Every Digit (0) | 2022.04.18 |
Sort Numbers (0) | 2022.04.17 |