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?
- A. 2
- B. 1
- C. 0
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A stack machine runs PUSH 3, PUSH 4, ADD, PUSH 5, MUL in order. The result is the value on top of the stack at the end. What is it?
- How many index pairs i < j in the array [1, 3, 1, 2, 3, 3] have a[i] = a[j]?
- What is the sum of the XOR of every non-empty contiguous subarray of [1, 2, 3]?
- How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?
- How many ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j}…
- What is the length of the longest prefix of the string ababbaba that is itself a palindrome?