Delete a Node from a Linked List

You are provided with a linked list of integers. Your task is to implement a function that deletes a node located at a specified position 'POS'.

Input:

The first line contains an integer 'T', indicating the number of test cases or queries. 
Each test case consists of two lines:
- First line: a sequence of integers representing the linked list elements separated by spaces.
- Second line: an integer 'POS', specifying the zero-based position from which the node should be removed.

Output:

For each test case, output the modified linked list as a sequence of integers separated by spaces, with each test case result on a new line.

Example:

Input:
2
3 2 5 1 -1
2
1 4 3 -1
0

Output:
3 2 1
4 3

Constraints:

  • 1 <= T <= 10^2
  • 0 <= N <= 10^5
  • POS >= 0

Note:

Indexing for the linked list begins at 0. If the position 'POS' is greater than or equal to the length of the linked list, the original linked list should remain unchanged.

The number -1 signifies the end of the linked list input and should not be included as a node in the list to be processed.

AnswerBot
4mo

Implement a function to delete a node from a linked list at a specified position.

  • Traverse the linked list to find the node at the specified position.

  • Update the pointers of the previous and next nodes ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at PayPal

Q. Given a list and a series of queries, how would you efficiently sort the list af...read more
Q. Given an array of numbers, find a subset of numbers that sum to zero.
Q. Explain how BFS works.
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits