Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Odd Even Linked List

Medium

Topics
Linked List

Given the head of a singly linked list, group all the nodes at odd positions together followed by the nodes at even positions (1-indexed), preserving relative order within each group. Return the reordered list.

Example 1

Input:  head = [1,2,3,4,5]
Output: [1,3,5,2,4]

Example 2

Input:  head = [2,1,3,5,6,4,7]
Output: [2,3,6,7,1,5,4]

Constraints

  • 0 <= number of nodes <= 10^4
  • -10^6 <= Node.val <= 10^6
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access