PIXELBANKv9.1.0
Menu

Remove Nth Node From End

Given an array representing a linked list and an integer n, remove the nth node from the end and return the modified list.

Output as space-separated integers, or empty if list becomes empty.

Example:

Input:
1,2,3,4,5
2
Output:
1 2 3 5
Reasoning:
  • The linked list is created from the input array: 1, 2, 3, 4, 5
  • We need to remove the nthn^{th} node from the end, where n=2n = 2, so we count from the end: 5 (1st), 4 (2nd)
  • The 2nd node from the end is the one with value 4, which is removed from the list
  • The modified list is then output as space-separated integers: 1, 2, 3, 5

Constraints:

  • 1 <= len(list) <= 30
  • 0 <= list[i] <= 100
  • 1 <= n <= len(list)
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Remove Nth Node From End - Medium | PixelBank