Move Low-Priority Jobs Behind Urgent Ones in a Linked Queue
Last updated: November 29, 2026
Quick Overview
A Borg-style job queue is a singly linked list of priority scores. Rearrange it so every job with score below a threshold x comes before every job with score at least x, preserving the original relative order inside each group.
0
0
0 solved
A Borg-style job queue is a singly linked list of priority scores. Rearrange it so every job with score below a threshold x comes before every job with score at least x, preserving the original relative order inside each group.
A Google technical screen problem that tests stable partitioning with pointers. The interviewer wants two dummy-headed sublists and a careful terminator on the second list, since leaving the old next pointer in place is the classic cycle bug.
What the Interviewer Expects
- Build two sublists with their own dummy heads
- Append each node to the correct sublist, preserving order
- Terminate the second list explicitly
- Concatenate in O(1)
- Explain why swapping values would not be stable
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Partition into three bands (< x, == x, > x).
- Do it on a doubly linked list.
- What if the queue is concurrently appended to by producers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head and threshold x.
- Output: head of the reordered list, nodes below x first, each group in original order.
- O(n) time, O(1) extra space, relink nodes....
High-Level Design
Walk the list once, appending each node to the tail of either the low list (score < x) or the high list. Because we only ever append, the original order inside each group is preserved, which is wh...