Data Structures & AlgorithmsVery hardTCS NQT · Infosys
In the sequence of queue operations enqueue 5, enqueue 3, dequeue, enqueue 8, dequeue, dequeue, enqueue 1, what is the value at the front of the queue afterwards (the queue is non-empty)?
- A. 2
- B. 1
- C. {C+5}
- D. 4
Correct answer: B. 1
After the operations, only 1 remains in the queue, so the front is 1. Stack order would give a different element.
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
- For the pattern "aabaabaaab" (0-based), what is the value of the KMP prefix function π at the LAST index? π[i] is the length of the…
- How many times does the pattern "aaa" occur in the text "aaaabaaaaab", counting OVERLAPPING occurrences (occurrences may share letters)?
- Using the Z-function (z[i] = length of the longest common prefix of s and s[i..], with z[0] = n), what is the sum of all z-values of…
- What is the length of the longest substring of "pwwkewfabcdbbca" with no repeated character?
- How many DISTINCT substrings (by content, non-empty) does "abcab" have?
- A polynomial hash is H(s) = (Σ ord(s[i]) · B^(n−1−i)) mod M, computed left to right as h = (h·B + ord(c)) mod M, with B = 31 and M =…