Reorder List

Data Structures
Medium
Microsoft
75.7K views

Given a singly linked list, reorder it in-place such that $L_0 \to L_n \to L_1 \to L_{n-1} \to \dots$. This requires multiple steps: find middle, reverse, and merge.

Why Interviewers Ask This

Microsoft asks this to evaluate a candidate's mastery of pointer manipulation and in-place algorithm design. It tests the ability to decompose complex logic into manageable sub-problems: finding the middle, reversing a sublist, and merging two lists without allocating extra memory. Interviewers specifically look for candidates who can handle edge cases like null pointers or single-node lists while maintaining O(1) space complexity.

How to Answer This Question

1. Clarify requirements immediately by confirming the input is a singly linked list and that reordering must be done in-place with O(1) extra space. 2. Propose a three-phase strategy explicitly: first, locate the middle node using the slow/fast pointer technique; second, reverse the second half of the list starting from the node after the middle; third, merge the first half and the reversed second half alternately. 3. Walk through the logic with a concrete example, such as [1, 2, 3, 4] becoming [1, 4, 2, 3], tracing pointer movements step-by-step. 4. Discuss time and space complexity analysis, emphasizing why this approach meets Microsoft's efficiency standards. 5. Address edge cases proactively, such as lists with zero, one, or two nodes, before writing any code.

Key Points to Cover

  • Explicitly state the O(1) space complexity requirement early in the discussion
  • Demonstrate the slow/fast pointer technique clearly for finding the middle
  • Show understanding of pointer manipulation during the reversal phase
  • Provide a concrete trace of the merging logic with a specific example
  • Proactively mention handling edge cases like null inputs or single nodes

Sample Answer

To solve this efficiently, I would break the problem down into three distinct phases to ensure clarity and correctness. First, I need to find the middle of the list. I'll use the classic slow and fast pointer approach wh…

Common Mistakes to Avoid

  • Attempting to use an auxiliary array or stack, which violates the O(1) space constraint
  • Failing to handle the case where the list has an odd number of nodes correctly during the merge
  • Breaking the link between the first and second half before reversing, causing data loss
  • Not checking for null pointers when moving to the next node, leading to runtime errors

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 166 Data Structures questionsBrowse all 107 Microsoft questions