Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Concise algorithm solution in Speedy category for Replace Last by Igor_Sekretarev
from typing import List
def replace_last(A: List) -> List:
for i in reversed(range(len(A)-1)):
A[i], A[i+1] = A[i+1], A[i]
return A
if __name__ == '__main__':
print("Example:")
print(replace_last([2, 3, 4, 1]))
# These "asserts" are used for self-checking and not for an auto-testing
assert replace_last([2, 3, 4, 1]) == [1, 2, 3, 4]
assert replace_last([1, 2, 3, 4]) == [4, 1, 2, 3]
assert replace_last([1]) == [1]
assert replace_last([]) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
April 30, 2021
Comments: