Data Structures & AlgorithmsHard

To count subarrays of length at least 2 with equal odd and even counts, why is the length-1 case excluded?

  1. A. A single element has one odd or one even value, so its balance cannot be zero; the zero-balance blocks must have at least two elements.
  2. B. Single elements are always odd.
  3. C. Length-1 blocks are not subarrays.
  4. D. The balance formula fails only for length 1 because of division.

Correct answer: A. A single element has one odd or one even value, so its balance cannot be zero; the zero-balance blocks must have at least two elements.

A block of length 1 has balance ±1, so it can never be zero, and the restriction is automatic. Stating it explicitly keeps the counting rule clean.

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

Exams that ask this topic