Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The list [5, 8, 1, 9, 3, 7, 2] is split into two halves (the first ⌈n/2⌉ elements and the rest). Each half is sorted, and the two sorted halves are merged. What is the value at index 3 of the merged list?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

Merging two sorted halves yields the fully sorted list, so index 3 of the merged result is the fourth smallest value overall. Taking index 3 of the unsorted halves is a different value.

More Coding Interview Problems questions

Exams that ask this topic