Facebook Pixel

Simulate Print Queue

You are managing a printer queue where print jobs are processed in FIFO (First In, First Out) order. Each job takes a certain number of pages to print. Given a list of jobs with their page counts, calculate the completion time for each job.

Input

  • jobs: a list of integers where each integer represents the number of pages in a print job

Output

A list of integers representing the completion time for each job (cumulative time when each job finishes)

Examples

Example 1:

Input: jobs = [5, 3, 8, 2]

Output: [5, 8, 16, 18]

Explanation:

  • Job 1 (5 pages): finishes at time 5
  • Job 2 (3 pages): finishes at time 5 + 3 = 8
  • Job 3 (8 pages): finishes at time 8 + 8 = 16
  • Job 4 (2 pages): finishes at time 16 + 2 = 18

Example 2:

Input: jobs = [10]

Output: [10]

Explanation:

  • Job 1 (10 pages): finishes at time 10

Example 3:

Input: jobs = [1, 1, 1, 1]

Output: [1, 2, 3, 4]

Explanation:

  • Job 1: finishes at time 1
  • Job 2: finishes at time 2
  • Job 3: finishes at time 3
  • Job 4: finishes at time 4

Try It Yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro