Rearrange odd and even places

Rearrange and return a linked list in such a way that all odd position nodes are together and all even positions node are together

You just need to return the head of new linked list, don't print the elements.

Input format :
Line 1 : Linked list elements of length n (separated by space and terminated by -1)
Output format :
Updated list elements (separated by space)
Constraints :

1 <= n <= 10^4

AnswerBot
1y

The task is to rearrange a linked list such that all odd position nodes are together and all even position nodes are together.

  • Create two separate linked lists, one for odd position nodes and one for e...read more

CodingNinjas
author
2y

Tip 1 : Constant communication
Tip 2 : Give a solution and then optimize it

CodingNinjas
author
2y
Space Complexity: Explanation: Time Complexity: Explanation:
Add answer anonymously...
Rupeek 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
Get AmbitionBox app

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