Problem Statement: Delete Node In A Linked List

Given a singly linked list of integers and a reference to a node, your task is to delete that specific node from the linked list. Each node in the linked list has a unique value.

Input:

The first line contains an integer 'T' indicating the number of test cases. For each test case, the first line consists of space-separated integers representing the linked list nodes, ending with -1 (which is not a part of the linked list node values). The second line contains an integer K, the value of the node to be deleted.

Output:

For each test case, after deleting the specified node, print the modified linked list's node values, separated by a single space, followed by '-1' to denote the end of the list. Each result should be printed on a new line.

Example:

Input:
2
4 5 1 9 -1
5
4 5 1 9 -1
1
Output:
4 1 9 -1
4 5 9 -1

Constraints:

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

Where 'N' denotes the number of nodes in the linked list and 'NODE.DATA' is the value of a node.

Note:

• The reference to the head of the linked list is not provided.
• The node to be deleted is not the tail node.
• Each node's value in the linked list is unique.
• The node to be deleted will always exist in the linked list.
Be the first one to answer
Add answer anonymously...
UnitedHealth 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