Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have a difference (max minus min) of at least 6?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Evaluate each window's max and min and test the difference. Windows of size two would give a different count.
More Coding Interview Problems questions
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is reduced by repeatedly removing the first two elements and appending their sum to the…
- Problem: For the sequence 2, 3, 5, 7, 11, …, the first 10 prime numbers are listed. What is the sum of the 10th and 7th primes in the list?
- Problem: A bitmask represents a subset of the 4 items {A, B, C, D} by bits 0–3. How many subsets have an even number of items and do NOT…
- Problem: Find the number of ways to select a non-empty subset of {1, 2, 4, 8, 16} whose sum is a multiple of 5.
- Problem: In the array [3, 5, 2, 8, 6, 1], the number of elements that are greater than every element after them (right leaders) is…