Data Structures & AlgorithmsVery hard

When counting subarrays, why do two blocks with identical values but different positions count as two different subarrays?

  1. A. A subarray is identified by its index range, so equal contents at different positions are distinct subarrays.
  2. B. Equal blocks are always merged into one subarray.
  3. C. Only distinct value patterns are subarrays.
  4. D. Subarrays are counted by their sums, so equal values collapse.

Correct answer: A. A subarray is identified by its index range, so equal contents at different positions are distinct subarrays.

The count is over index ranges [l, r], which is why methods such as prefix-sum hashing count positions and not patterns. Collapsing equal contents would answer a different question.

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

Exams that ask this topic