Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #328: Odd Even Linked List

In this guide, we solve Leetcode #328 Odd Even Linked List in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on.

Quick Facts

  • Difficulty: Medium
  • Premium: No
  • Tags: Linked List

Intuition

Linked list problems often require pointer manipulation rather than extra memory.

Two-pointer techniques expose cycles, midpoints, or reordering patterns.

Approach

Traverse with fast/slow pointers or reverse sublists when needed.

Maintain invariants carefully to avoid losing nodes.

Steps:

  • Traverse with pointers.
  • Reverse or split if required.
  • Reconnect nodes correctly.

Example

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

Python Solution

# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]: if head is None: return None a = head b = c = head.next while b and b.next: a.next = b.next a = a.next b.next = a.next b = b.next a.next = c return head

Complexity

The time complexity is O(n)O(n)O(n), where nnn is the length of the list, and we need to traverse the list once. The space complexity is O(1)O(1)O(1).

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy