Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.
- A. 31
- B. 6
- C. 4
- D. 11
Correct answer: B. 6
The five windows have minima 1, 1, 1, 1, 2, summing to 6 (a monotonic deque gives O(n)). Summing window maxima gives 31, missing the last window gives 4, and using window size 2 gives 11.
More Coding Interview Problems questions
- Problem: The Euclidean algorithm is run on (1071, 462). How many division steps (a mod b operations) are performed until the remainder…
- Problem: Count the subarrays of [4, 2, 2, 4, 2] whose maximum equals the minimum (single elements count).
- Problem: Water is poured into the cells of a 1-dimensional array of heights [0,1,0,2,1,0,1,3,2,1,2,1]; each cell holds water up to…
- Problem: Starting at 0 on a line, a walker takes steps +3, −2, +3, −2, … alternating, with 12 steps in total. How many distinct integer…
- Problem: Count the sequences of length 5 over {0, 1, 2} with no two adjacent equal digits and whose first digit is 0.
- Problem: The sorted array [1, 4, 4, 9, 12, 12, 15, 20] (0-indexed) may contain repeated values. Using a lower-bound search, which returns…