Data Structures & AlgorithmsHard
How many contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100? Every value is a positive integer.
- A. 4
- B. 9
- C. 7
- D. 8
Correct answer: D. 8
With positive values the window [left..right] is valid for every start from left to right, so each right end adds right−left+1. Counting one subarray per right end undercounts, and using ≤ instead of < admits the subarray 10·5·2 = 100 that must be excluded.
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 sum of the sums of all contiguous subarrays of [999999999, 888888888, 777777777], taken modulo 1000000007?
- What is the sum, over all contiguous subarrays of [3, 1, 3, 2], of the maximum element of each subarray?
- In [4, 7, 5, 9, 6, 3], how many contiguous subarrays have (max − min) ≤ 3?
- How many contiguous subarrays of [1, 2, 1, 3, 3, 2, 2, 1] contain at most 2 distinct values?
- For the array [1, 3, 2, 6, 7, 4, 8, 12, 5], how many index pairs i < j have (J[i] + J[j]) divisible by 4?
- In the binary array [1, 0, 0, 1, 0, 1, 1, 0, 0, 0], how many contiguous subarrays contain equal numbers of 0s and 1s?