In [5]:
def countBits(n):
count = 0
while n > 0:
count += (n & 1)
n = n >> 1
return count
In [6]:
print countBits(1234)
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.
remove_smallest([1,2,3,4,5]) = [2,3,4,5]
remove_smallest([5,3,2,1,4]) = [5,3,2,4]
remove_smallest([2,2,1,2,1]) = [2,2,2,1]
In [7]:
def remove_smallest(numbers):
if len(numbers) < 1:
return numbers
idx = numbers.index(min(numbers))
return numbers[0:idx] + numbers[idx+1:]
In [8]:
print remove_smallest([5,3,2,1,4])
In [ ]: