← Reddit Interview Insights

Reddit·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Reddit ML Engineer interview with a linked list problem that looks straightforward but has a few gotchas if you're not careful about pointer manipulation.

Questions Asked (1)

Q1

Given the head of a singly linked list, reorder it so all odd-indexed nodes come first followed by all even-indexed nodes, preserving relative order within each group. Must run in O(n) time and O(1) space.

Algorithms & Data Structures
Author's notes

I knew the general idea pretty fast: keep two pointers, one crawling odd nodes and one crawling even, then stitch the even chain onto the end of the odd chain.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use two pointers to separate odd and even indexed nodes into two sublists while traversing the original list once. Then connect the end of the odd list to the head of the even list. This achieves O(n) time and O(1) space by rearranging pointers in place.

Pro tip: Clarify whether indices are 1-based or 0-based, as this affects which nodes are considered odd/even. Also, handle edge cases like empty list, single node, or two nodes to avoid null pointer exceptions.

1. Clarify problem and edge cases

Confirm indexing convention (1-based vs 0-based) and discuss edge cases such as empty list, single node, or two nodes. This ensures correct interpretation and robust handling.

2. Initialize pointers

Create pointers for odd and even lists: oddHead, oddTail, evenHead, evenTail. Start with the first node as odd and second as even, if they exist.

3. Traverse and separate

Iterate through the list, linking odd nodes to the odd list and even nodes to the even list, updating tails accordingly. Advance by two nodes each step.

4. Combine lists

After traversal, connect the tail of the odd list to the head of the even list. Ensure the last node of the even list points to null to terminate the list.

5. Return result and test

Return the head of the odd list (or even list if odd is empty). Walk through an example to verify correctness and edge cases.

Key Points to Mention

  • Time complexity O(n) and space complexity O(1) due to in-place pointer manipulation.
  • Use of two pointers (or four pointers) to maintain separate odd and even lists.
  • Handling of edge cases: empty list, single node, two nodes.
  • Preservation of relative order within odd and even groups.
  • Clarification of indexing convention (1-based vs 0-based) as it affects the solution.
  • Avoiding null pointer dereferences by checking for null before accessing next pointers.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.