Data Structures & AlgorithmsHardTCS NQT · Infosys
A queue has capacity 4 and an enqueue into a full queue is rejected. Operations in order: enqueue 1, 2, 3, 4; dequeue; dequeue; enqueue 5; enqueue 6; dequeue; enqueue 7. What is the front element of the queue afterwards?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Track the contents explicitly: after the two dequeues only 3 and 4 remain, and the front changes each time a dequeue happens.
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
- What is the sum of the maxima of every contiguous window of size 3 in the array [1, 3, -1, -3, 5, 3, 6, 7]?
- How many valid sequences of 4 push and 4 pop operations are there on an initially empty stack, where every pop is applied only to a…
- Three processes arrive at time 0 with CPU bursts 5, 3 and 8. Round-robin scheduling uses a time quantum of 2, a process that is not…
- Remove exactly 3 digits from the number 1432219 (without reordering the rest) so that the remaining number is as small as possible. What…
- Repeatedly delete any two adjacent equal characters from the string abbacbaca until no such pair exists. How many characters remain?
- How many substrings of length exactly 4 of the string abbaccddcc are palindromes?