Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the value (sum of the two smallest elements). Perform this for 3 full rounds (each round is one removal then one append). What is the sum of all elements at the end?
- A. 96
- B. 40
- C. 29
- D. 141
Correct answer: C. 29
Round 1 removes 36 and appends 1 + 4 = 5; rounds 2 and 3 remove 25 then 16 and append 5 each time, leaving [1, 4, 9, 5, 5, 5] with sum 29. Appending the two LARGEST instead gives 96, stopping after two rounds gives 40, and removing the smallest element gives 141.
More Coding Interview Problems questions
- Problem: A simple graph has 6 vertices labelled 1–6. Vertex i is adjacent to j exactly when gcd(i, j) = 1 and i ≠ j. How many edges does…
- Problem: What is the number of inversions in the array [6, 2, 8, 1, 9, 4, 3, 7, 5]? (An inversion is a pair of indices i < j with a[i] >…
- Problem: Using a single counter, a sequence of commands is applied to the value x = 0: "+5", "×2", "−3", "×2", "+1", "÷4" (integer…
- Problem: In a binary max-heap stored in an array with 1-based indexing, the array is [40, 30, 35, 10, 20, 25, 28, 5, 8, 12]. An operation…
- Problem: In the array [3, 8, 1, 9, 4, 7, 2, 6, 5], what is the length of the longest subarray whose sum is exactly 20?
- Problem: A sorted list 2, 4, 6, 8, 10, 12, 14 is treated as a rotated array: the first 3 values are moved to the end, giving 8, 10, 12…