Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: The array [1, 5, 2, 6, 3, 7, 4, 8] is split into two halves, [1, 5, 2, 6] and [3, 7, 4, 8]. The result is formed by interleaving them, taking the first half's element before the second half's element each time. What is the element at index 2 of the result?

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

Correct answer: C. 5

The interleave takes one element from the first half and then one from the second, so the result starts 1, 3, 5, 7, ... Index 2 therefore holds the second element of the first half, which is 5.

More Coding Interview Problems questions

Exams that ask this topic