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!
Add answer anonymously...
Goldman Sachs Software Developer interview questions & answers
A Software Developer was asked 2mo agoQ. Given an array, remove elements that appear consecutively for more than k times....read more
A Software Developer was asked 12mo agoQ. What is the difference between OOP and POP?
A Software Developer was asked Q. Write a function to select a pivot element randomly in Quick Sort.
Popular interview questions of Software Developer
A Software Developer was asked 2mo agoQ1. Given an array, remove elements that appear consecutively for more than k times....read more
A Software Developer was asked 12mo agoQ2. What is the difference between OOP and POP?
A Software Developer was asked Q3. Write a function to select a pivot element randomly in Quick Sort.
>
Goldman Sachs Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

