Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A list starts as [8, 3, 5]. Three insertion steps add the numbers 4, 9, 1 at the front of the list (each is inserted at index 0), and then the list is sorted in increasing order. What is the median of the final sorted list?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Insert each value at the front, sort, and take the middle element of the six-element list. Sorting the original list alone gives a different median.
More Coding Interview Problems questions
- Problem: A deque starts as [2, 4, 6]. The operations are: push front 1, push back 8, pop front, push back 3. What is the sum of the final…
- Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?
- Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the…
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.
- Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9] is split into 3 consecutive groups of equal length. What is the sum of the middle group?