Find When Your Job Prints From a Priority Print Queue
Last updated: November 29, 2026
Quick Overview
A shared office printer holds a queue of jobs with priorities. It takes the front job and prints it only if no remaining job has a higher priority; otherwise the job moves to the back. Return the 1-based print order position of the job at index location.
0
0
0 solved
A shared office printer holds a queue of jobs with priorities. It takes the front job and prints it only if no remaining job has a higher priority; otherwise the job moves to the back. Return the 1-based print order position of the job at index location.
An online assessment style queue simulation in a Google workplace framing. It checks whether you can keep track of identity while elements rotate, and whether you can make the max-priority check cheaper than rescanning the whole queue.
What the Interviewer Expects
- Carry the original index with each job through the rotation
- Implement the rotate-or-print rule exactly
- Use a priority count array or sorted list to find the current max fast
- Return a 1-based position
- Explain the worst case of the naive approach
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
- How would you produce the complete print order?
- What if new jobs can arrive while the printer runs?
- How would you add aging so low-priority jobs cannot starve?
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: list priorities (ints, say 1 to 9) and an index location. Rule: pop the front job; if any job still in the queue has a strictly higher priority, push it to the back; otherwise print it. Out...
High-Level Design
Use a deque of (priority, index) pairs. To know the current highest priority without scanning, keep count[p] for each priority and a pointer top that moves down whenever count[top] hits zero. ...