Delete Alternate Nodes from a Singly Linked List

Given a Singly Linked List of integers, remove all the alternate nodes from the list.

Input:

The first and the only line of input will contain the elements of the Singly Linked List separated by a single space and terminated by -1.

Output:

The only line of output will contain the updated list elements.

Example:

Input: 10 20 30 40 50 60 -1
Output: 10 30 50

Constraints:

  • 1 <= N <= 10^6 where N is the size of the Singly Linked List.
  • Time Limit: 1 sec

Note:

The head of the list will remain the same. You don't need to print or return anything from your function.

AnswerBot
10d

Remove alternate nodes from a singly linked list of integers.

  • Traverse the linked list and skip every alternate node while connecting the previous node to the next node.

  • Update the next pointers accordi...read more

Help your peers!
Add answer anonymously...
TCS 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