Delete the Middle Node from a Singly Linked List
Given a singly linked list of integers, the task is to remove the middle node from this list.
Input:
The first line of input includes an integer 'T' which denotes the number of test cases.
Each test case consists of a single line containing the linked list elements separated by spaces, ending with -1 (which is not part of the list).
Output:
For every test case, produce the updated linked list after removing the middle node, separated by spaces and terminating with -1.
Render the output for each test case on a distinct line.
Example:
Input:
2
1 3 4 7 1 2 6 -1
1 2 3 4 -1
Output:
1 3 4 1 2 6 -1
1 2 4 -1
Constraints:
- 1 <= T <= 100
- 0 <= L <= 5000
- 1 <= data <= 109 and data ≠ -1
Notes:
1. Return an empty list (i.e., NULL) if no middle node to delete exists.
2. If there are two middle nodes, remove the first one.
Follow-up: Can you achieve the solution in O(N) time and O(1) space complexity with just a single traversal of the list?

AnswerBot
1y
The task is to delete the middle node of a singly linked list of integers.
If the linked list is empty or has only one node, there is no middle node to delete.
To delete the middle node, we need to find...read more
Help your peers!
Add answer anonymously...
Adobe Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more
A Software Developer was asked 9mo agoQ. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the...read more
A Software Developer was asked 12mo agoQ. Given a sorted two-dimensional array, find the index of a given element or retur...read more
Popular interview questions of Software Developer
A Software Developer was asked 9mo agoQ1. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more
A Software Developer was asked 9mo agoQ2. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the...read more
A Software Developer was asked 12mo agoQ3. Given a sorted two-dimensional array, find the index of a given element or retur...read more
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

