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
4mo

Remove the middle node from a singly linked list of integers.

  • Identify the middle node using slow and fast pointers.

  • Remove the middle node by adjusting the pointers.

  • Handle cases where there are two mid...read more

Help your peers!
Select
Add answer anonymously...

GoMechanic Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Different Ways To Add Parenthesis Suppose you have a string 'S' representing an ...read more
A Software Developer Intern was asked Q. Time to Burn Tree Problem You are given a binary tree consisting of 'N' unique n...read more
A Software Developer Intern was asked Q. Delete the Middle Node from a Singly Linked List Given a singly linked list of i...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Different Ways To Add Parenthesis Suppose you have a string 'S' representing an ...read more
A Software Developer Intern was asked Q2. Time to Burn Tree Problem You are given a binary tree consisting of 'N' unique n...read more
A Software Developer Intern was asked Q3. Delete the Middle Node from a Singly Linked List Given a singly linked list of i...read more
GoMechanic Software Developer Intern 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