Process print jobs in arrival order
Python data engineering interview problem. Difficulty: beginner. Pattern: Streaming. About 10 minutes. Free to practice.
A print shop queues jobs in arrival order. The first job that arrived should print first; later jobs wait.
A print server receives jobs as pairs of a job name and a number of pages. Jobs are printed in the order they arrive. Return the names of the jobs in the order they were received. The page count is part of the input, but it does not change the order. Write print_order(jobs). For [('job-a', 3), ('job-b', 1)] the result is ['job-a', 'job-b']. An empty list gives []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Return the job names only.
- Keep the arrival order.
- Ignore the page counts for the order.
- Return [] for no jobs.
Constraints
- jobs is a list of (name, pages) pairs.
- This is a first-in, first-out queue.
Examples
Input: print_order([('job-a', 3), ('job-b', 1)]) Output: ['job-a', 'job-b'] This input follows the stated rules and produces this output.
Topics: lakebench, python, queue.
More Python interview questions · All interview problems · Learn data engineering
Process print jobs in arrival order
Interview-style drill: Simulate a first-in-first-out print queue and return the order jobs are printed.
Process print jobs in arrival order and return the processing sequence the tests expect.