Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
Two sorted linked lists [8 → 33 → 35 → 40] and [2 → 13 → 16] are merged with the standard O(n+m) two-pointer merge (always take the smaller head, splicing nodes, no new array). What is the merged list?
- A. 2 → 8 → 13 → 16 → 33 → 35 → 40
- B. 8 → 33 → 35 → 40 → 2 → 13 → 16
- C. 8 → 2 → 33 → 13 → 35 → 16 → 40
- D. 40 → 35 → 33 → 16 → 13 → 8 → 2
Correct answer: A. 2 → 8 → 13 → 16 → 33 → 35 → 40
At each step the merge compares the current heads of both lists and splices the smaller one onto the result, advancing only that list's pointer; this produces the fully sorted list [2 → 8 → 13 → 16 → 33 → 35 → 40] in one linear pass. Simply concatenating the two lists, [8 → 33 → 35 → 40 → 2 → 13 → 16], is not sorted.
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 circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(2), enqueue(6), dequeue(), dequeue(), enqueue(1)…
- Keys 13, 28, 91, 42, 33 are inserted via linear probing (h(k) = k mod 7, probe by +1 on collision) into an initially empty table of size 7…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(8), enqueue(2), enqueue(5), dequeue(), enqueue(1)…