Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Nothing special solution in Uncategorized category for Reverse Every Ascending by Kolia951
from typing import Iterable
def reverse_ascending(data: list[int]) -> Iterable[int]:
temp = []
final_list = []
if len(data) == 1:
return data
for i in range(1, len(data)):
if data[i-1] == data[i] or data[i-1] > data[i]:
if i + 1 < len(data):
temp.append(data[i-1])
temp.sort(reverse=True)
final_list.extend(temp)
temp.clear()
else:
temp.append(data[i-1])
temp.sort(reverse=True)
final_list.extend(temp)
final_list.append(data[i])
elif data[i-1] < data[i]:
temp.append(data[i-1])
if i + 1 == len(data):
temp.append(data[i])
temp.sort(reverse=True)
final_list.extend(temp)
return final_list
print("Example:")
print(list(reverse_ascending([1, 2, 3, 4, 5])))
assert list(reverse_ascending([1, 2, 3, 4, 5])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([5, 7, 10, 4, 2, 7, 8, 1, 3])) == [
10,
7,
5,
4,
8,
7,
2,
3,
1,
]
assert list(reverse_ascending([5, 4, 3, 2, 1])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([])) == []
assert list(reverse_ascending([1])) == [1]
assert list(reverse_ascending([1, 1])) == [1, 1]
assert list(reverse_ascending([1, 1, 2])) == [1, 2, 1]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 12, 2022