Data Structures & AlgorithmsVery hard
How many contiguous windows of length exactly 4 in 6 2 5 9 4 7 3 satisfy (maximum − minimum) ≤ 3?
- A. 4
- B. 1
- C. 0
- D. 2
Correct answer: C. 0
Each fixed window of length 4 is checked on its own max and min, and the bound is inclusive. Using a strict bound, changing the window length, or counting the complement each give other values.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum product of two ADJACENT elements of 5 3 8 2 9 4?
- How many index pairs i < j in 1 2 3 4 5 6 satisfy A[i] AND A[j] = 0 (bitwise AND)?
- What is the sum, over all non-empty contiguous subarrays of 1 3 5, of the bitwise OR of each subarray?
- How many DISTINCT values arise as the bitwise OR of a non-empty contiguous subarray of 1 2 4 2?
- How many index pairs i < j in 3 5 6 1 4 2 satisfy A[i] OR A[j] = 6, the maximum value of the array?
- Consider the windows of length 3 of 1 2 3 1 2 4 1 2 starting at positions i and i+1. How many i satisfy sum(window i) = sum(window i+1)?