Data Structures & AlgorithmsHardTCS NQT · Accenture
Two queues hold [1, 3, 5] and [2, 4, 6]. The output takes one element from the first queue, then one from the second, alternately, until both are empty. What is the value at position 4 of the output (1-based)?
- A. 5
- B. 6
- C. 8
- D. 4
Correct answer: D. 4
Interleaving the queues gives 1, 2, 3, 4, 5, 6, so position 4 (1-based) holds 4. Reading the position as a 0-based index gives 5, the most tempting slip; 6 is the last element and 8 is in neither queue.
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
- Which technique gives O(1) time per query for 'sum of a[l..r]' on a static array after O(n) preprocessing?
- Given an array that may contain negative numbers, which method counts the subarrays whose sum equals exactly k in O(n) expected time?
- Which structure returns the maximum of every window of size k in a sliding pass in O(n) total time?
- To test whether string s2 is a rotation of string s1 in linear time, which approach is standard?
- For each element of an array of distinct integers, the task is to count how many earlier elements are smaller. Which structure achieves…
- What is the length of the longest common subsequence of the three strings "ABCBDAB", "BDCABA" and "BCADB"?