Data Structures & AlgorithmsHardTCS NQT · Infosys

A print queue holds jobs with priorities [2, 1, 3, 2] (index 0 to 3). The front job prints only if no waiting job has a higher priority; otherwise it moves to the back. Which job index is printed last?

  1. A. 2
  2. B. 1
  3. C. 0
  4. D. 3

Correct answer: B. 1

Simulate the queue: job 2 (priority 3) prints first, then the rest in the order their priorities allow. The last printed job is the lowest-priority one that waits the longest.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic