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?
- A. 5
- B. 6
- C. 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
- Problem: Compute the sum of the integers from 1 to 1000 that are divisible by 7 or by 11 but not by 77.
- Problem: How many distinct values does the expression (i j) mod 7 take as i and j range independently over 1 ≤ i, j ≤ 7?
- Problem: What does the following print? python x = [[0] 2] 2 x[0][1] = 5 print(x)
- Problem: What does the following print? python print(0.1 + 0.2 == 0.3, round(2.5), round(3.5))
- Problem: What does the following print? python a = [1, 2, 3] b = a b += [4] print(a)
- Problem: What does the following print? python print(int('0b101', 0), int('101', 2), 7 // 2 2)