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?
- A. 6
- B. 4
- C. 5
- 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
- Problem: How many integers from 1 to 1000 are perfect squares or perfect cubes (counted once even if both)?
- Problem: An undirected graph has edges 0-1, 1-2, 2-3, 3-4, 4-0, 1-5, 5-6, 6-2. What is the length of the shortest cycle that passes…
- Problem: In a directed graph with arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, the strongly connected components are formed. What is the size of the…
- Problem: The tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7, 6-8 is rooted at node 1. How many nodes have exactly two neighbours (degree 2)…
- Problem: How many occurrences of the substring "ana" are in "bananarama" (overlapping occurrences count)?
- Problem: How many distinct strings formed by permuting the letters of "aab" are palindromes?