...

/

Untitled Masterpiece

Try to solve the Remove Nth Node from End of List problem.

Statement

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

Constraints:

  • The number of nodes in the list is kk.
  • 11 \leq kk 103\leq 10^3
  • 103-10^3 \le Node.value 103\le 10^3
  • 11 \le n \le kk

Examples

Press + to interact
canvasAnimation-image
1 / 4

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Remove Nth Node From End of List

1

What is the output if the following linked list and value of nn are given as input?

Linked list: 32 → 78 → 65 → 90 → 12 → 44 → NULL

nn = 3

A)

32 → 78 → 90 → 12 → 44 → NULL

B)

32 → 78 → 65 → 12 → 44 → NULL

C)

78 → 65 → 90 → 12 → 44 → NULL

D)

32 → 78 → 65 → 90 → 12 → NULL

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in the following coding playground.

Press + to interact
Python
usercode > Solution.py
# Definition for a Linked List node
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
from ds_v1.LinkedList.LinkedList import ListNode
def remove_nth_last_node(head, n):
# Replace this placeholder return statement with your code
return None
Remove Nth Node from End of List

Access this course and 1200+ top-rated courses and projects.