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?

  1. A. 9
  2. B. 10
  3. C. 11
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic