Remove Nth Node From End of List

Medium Solved

Description

Given the head of a linked list, remove the nth node from the end of the list and return the head of the modified list.

The input linked list is represented as an array.

Input format / Clarification:

  • Line 1: JSON array representing linked list
  • Line 2: Integer n

Examples

Input:
[1,2,3,4,5]
2
Output:
[1,2,3,5]
Input:
[1]
1
Output:
[]
Input:
[1,2]
1
Output:
[1]

Note:

Your program must print the final linked list as a JSON array.
print(str(fuctionname(x)).replace(" ", ""))

No submissions yet.

Discuss two-pointer technique, dummy node usage, and single-pass optimization.

Test Cases