Created
April 16, 2018 18:29
Answer to cassidoo interview question for 4.9.2018
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
# Given an unsorted array arr and a number n, | |
# delete all numbers in arr that are greater than n. | |
arr = [3,4,6,1,8,2,6,7,10] | |
num = 7 | |
def deleteElements(arr, num): | |
for x in arr: | |
if x > num: | |
arr.remove(x) | |
return arr | |
print deleteElements(arr, num) | |
# Alternative way that generates a new list without altering original | |
newArr = list(filter(lambda x : x <= num, arr)) | |
print newArr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment