Remove From the End
In linked-list style questions, you often need to remove an element by counting from the end instead of the beginning. Here, the linked list is represented as a regular list of values lst, and n tells which element from the end to remove. Remove that element and return the resulting list of values; n is guaranteed to be valid.
Примеры
Ввод
[1, 2, 3, 4, 5], 2Вывод
[1, 2, 3, 5]Ввод
[1], 1Вывод
[]Ввод
[1, 2], 1Вывод
[1]Нужно реализовать
def remove_nth_from_end(lst, n):
Теги
arraytwo-pointerslists
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
[1,2,3,4,5], 2Expected
[1,2,3,5]2
Input
[1], 1Expected
[]3
Input
[1,2], 1Expected
[1]4
Input
[1,2], 2Expected
[2]5
Input
[7,8,9,10], 4Expected
[8,9,10]6
Input
[1,2,3,4,5], 1Expected
[1,2,3,4]Focus radio
Paused · SomaFM · Fluid