Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sort by Removing by jusha
def sort_by_removing(values: list) -> list:
answer = []
if len(values) != 0:
answer.append(values[0])
p = values[0]
for i in range(1,len(values)):
if values[i] >= p:
answer.append(values[i])
p=values[i]
return answer
if __name__ == '__main__':
print("Example:")
print(sort_by_removing([3, 5, 2, 6]))
# These "asserts" are used for self-checking and not for an auto-testing
assert sort_by_removing([3, 5, 2, 6]) == [3, 5, 6]
assert sort_by_removing([7, 6, 5, 4, 3, 2, 1]) == [7]
assert sort_by_removing([3, 3, 3, 3]) == [3, 3, 3, 3]
assert sort_by_removing([5, 6, 7, 0, 7, 0, 10]) == [5, 6, 7, 7, 10]
assert sort_by_removing([1, 5, 2, 3, 4, 7, 8]) == [1, 5, 7, 8]
assert sort_by_removing([1, 7, 2, 3, 4, 5]) == [1, 7]
assert sort_by_removing([]) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
June 5, 2020
Comments: