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
PostgreSQLv16

Your code output will appear here

Visible tests
1
Input
[1,2,3,4,5], 2
Expected[1,2,3,5]
2
Input
[1], 1
Expected[]
3
Input
[1,2], 1
Expected[1]
4
Input
[1,2], 2
Expected[2]
5
Input
[7,8,9,10], 4
Expected[8,9,10]
6
Input
[1,2,3,4,5], 1
Expected[1,2,3,4]
Focus radio
Paused · SomaFM · Fluid