Dsa
Linked List
Warm-up
Remove N-th Node from End of List
Given a linked list, you need to remove the n-th node from the end of the list. The linked list nodes are represented as space-separated integers followed by -1. You will be given the value of n on a new line.
Input format:
- A single line containing integers representing the linked list followed by -1.
- Second line contains a single integer n.
Output format:
- A single line of space-separated integers representing the linked list after the removal. If n is not valid (greater than the number of nodes), return the original linked list.
Example:
Input:
1 2 3 4 5 -1
2
Output:
1 2 3 5
Key concepts
linked_listremovaltraversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now