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.

Be the first one to answer
Add answer anonymously...
Goldman Sachs Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter