Stable Partition of a Linked Queue Around a Priority Threshold

Last updated: November 29, 2026

Quick Overview

Given the head of a linked list of job priorities and a threshold x, reorder it so all nodes with value less than x come before nodes with value at least x, preserving relative order within each group.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given the head of a linked list of job priorities and a threshold x, reorder it so all nodes with value less than x come before nodes with value at least x, preserving relative order within each group.

A Meta phone-screen problem framed as promoting urgent jobs ahead of the rest in a linked work queue without disturbing their order. The interviewer checks that you build two sublists with dummy heads and terminate the second one to avoid a cycle.

What the Interviewer Expects
  • Use two dummy heads for the small and large groups
  • Append nodes to the correct tail in one pass
  • Terminate the large list's tail
  • Concatenate small then large
  • Keep relative order stable
Key Topics to Cover
Linked list
Partitioning
Dummy node
Stability
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Partition into three groups (less, equal, greater).
  • Do it without dummy nodes.
  • Why is stability important if downstream consumers rely on FIFO within a priority?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: head of a list and integer x. Output: head of the relinked list where every value < x precedes every value >= x, and within each group nodes keep their original order. Reuse existing nodes;...

High-Level Design

Walk the list once and detach each node onto one of two chains: small for values below x and large for the rest. Dummy heads mean each chain starts non-empty, so appending is always `tail.next = n...


Submit Your Answer
Markdown supported