Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
For an array of length 5 indexed 0 to 4, how many contiguous subarrays contain index 2?
- A. 9
- B. 10
- C. 11
- D. 6
Correct answer: A. 9
A subarray [i..j] contains index 2 when i is in 0..2 and j is in 2..4, giving 3 * 3 = 9. Counting all subarrays of length at least 3 (the last option) is a different count.
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
- Among integers from 1 to 40 inclusive, which value has the largest number of 1-bits in binary? Report the smallest such value.
- How many index pairs i < j of [1, 2, 3, 4, 6, 6] satisfy a[i] a[j] = a[i] + a[j]?
- How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?
- Closed meeting intervals [1,3], [3,4], [2,5], [6,7] cannot share a room if they overlap even at one point. What is the minimum number of…
- How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?
- In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?