Data Structures & AlgorithmsVery hardTCS NQT · Accenture
Apply the reversal of the first 4 elements to the queue 1, 2, 3, 4, 5, 6, 7, 8 (front first). What is the element at position 6 of the resulting queue (1-based)?
- A. 6
- B. 7
- C. 5
- D. 9
Correct answer: A. 6
Reversing the first 4 gives 4, 3, 2, 1, 5, 6, 7, 8; the reversal uses a stack for the first k elements and then re-enqueues the rest in order.
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 array [1, 3, 2, 4], take the next strictly greater element of each position (-1 if none) and sum these values, ignoring the -1…
- What is the sum of the minimum of every contiguous window of length 2 in the array [3, 1, 4, 1, 5, 9, 2, 6]?
- A singly linked list contains the people 1 to 12 in a circle. Starting from person 1, every 4th person is removed (the count starts at 1)…
- How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?
- In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i]…
- How many strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by…