Data Structures & AlgorithmsVery hard
How many contiguous subarrays of 0 1 2 0 1 2 have a sum between 3 and 5 inclusive?
- A. 9
- B. 10
- C. 3
- D. 12
Correct answer: B. 10
Zeros create many subarrays with equal sums, so the counting must treat each start and end pair separately. Using a strict bound on either end, or ignoring the upper bound, each change the total.
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
- How many NON-EMPTY subsequences of 3 1 4 1 5 9 (position subsets read in order) are STRICTLY increasing?
- How many NON-EMPTY subsequences of 2 3 4 7 8 5 (position subsets read in order) alternate in parity, so that each chosen value has the…
- How many subsequences of EXACTLY three elements of 1 4 2 5 7 9 6 (position subsets read in order) form an arithmetic progression (the…
- How many NON-EMPTY subsequences of 2 5 3 8 6 1 (subsets chosen by position) have (maximum − minimum) exactly 3?
- How many NON-EMPTY subsets of 1 2 3 4 5 6 7 have bitwise XOR equal to 0?
- How many subsets of exactly two elements of 2 4 5 7 9 10 12 (position pairs) have a sum divisible by 3?