← Reddit Interview InsightsMachine Learning Engineer

Reddit·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Reddit ML Engineer interview with a linked list problem that sounds easy until you actually think about the space constraint. Pretty standard technical screen vibe but the O(1) space requirement is what tripped me up mentally.

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) extra space.

Algorithms & Data Structures
Author's notes

My first instinct was to just collect nodes into two arrays and stitch them together, which obviously blows the space requirement.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use two pointers to build separate odd and even lists by rewiring next pointers, then connect the odd list's tail to the even list's head. Maintain pointers to the heads and tails of both lists to preserve order and achieve O(1) space.

Pro tip: Explicitly state the edge cases (empty list, single node, two nodes) and walk through a small example to demonstrate correctness before coding. This shows thoroughness and helps catch off-by-one errors.

1. Clarify and handle edge cases

Confirm the definition of odd/even indexing (1-based vs 0-based) and check if the list is empty or has fewer than 3 nodes, in which case return the head as is.

2. Initialize pointers

Set odd_head and even_head to the first and second nodes respectively. Use odd_tail and even_tail to build the lists, and a current pointer to traverse.

3. Traverse and rewire

Iterate through the list, alternating between appending to the odd list and the even list by updating next pointers. Advance current by two steps each time.

4. Connect the lists

After traversal, set the next pointer of the odd list's tail to the head of the even list, and ensure the even list's tail points to null.

5. Return and verify

Return the head of the odd list. Walk through a small example to verify the reordering and check that the time and space complexity meet the requirements.

Key Points to Mention

  • Time complexity O(n) because each node is visited once.
  • Space complexity O(1) because only a constant number of pointers are used.
  • Preservation of relative order within odd and even groups.
  • Handling of edge cases: empty list, single node, two nodes.
  • Use of dummy nodes or direct pointer manipulation to simplify rewiring.
  • Potential pitfalls: losing references to nodes when rewiring, and ensuring the even list's tail is set to null.

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