Delete a Node in a Linked List

Given a reference to a node in a singly linked list, your task is to delete that node. Every node in the list has a unique value. The head of the linked list will not be provided.

Input:
The first line contains an integer 'T' indicating the number of test cases. Each test case consists of two lines: The first line contains space-separated integers representing the values of the linked list nodes, ending in -1, indicating the end of the list. The second line contains a single integer K indicating the value of the node to be deleted.
Output:
For each test case, output the updated list of node values separated by a space, ending with '-1'. Each result should be on a new line.
Example:
Input:
2
4 5 1 9 -1
5
1 2 3 4 -1
3
Output:
4 1 9 -1
1 2 4 -1

Constraints:

  • 1 <= T <= 100
  • 2 <= N <= 5000
  • -109 <= NODE.DATA <= 109 and NODE.DATA != -1
Note:

No need to print anything yourself. Implement the function as requested.

AnswerBot
4mo

To delete a node in a singly linked list given a reference to the node.

  • Traverse the linked list to find the node to be deleted.

  • Update the value of the node to be deleted with the value of the next nod...read more

Help your peers!
Select
Add answer anonymously...

Paytm Software Developer interview questions & answers

A Software Developer was asked 4mo agoQ. Given a sorted array of integers nums and an integer target, write a function to...read more
A Software Developer was asked 6mo agoQ. What is multithreading?
A Software Developer was asked 7mo agoQ. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more

Popular interview questions of Software Developer

A Software Developer was asked 4mo agoQ1. Given a sorted array of integers nums and an integer target, write a function to...read more
A Software Developer was asked 6mo agoQ2. What is multithreading?
A Software Developer was asked 7mo agoQ3. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more
Paytm 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