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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

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
queue simulation
deque
priority
counting array
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
  • 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 Problems
Sample 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. ...


Submit Your Answer
Markdown supported