Data Structures & AlgorithmsVery hard

How many contiguous subarrays of length exactly 3 in 1 2 1 3 3 2 3 1 1 read the same forwards and backwards?

  1. A. 1
  2. B. 5
  3. C. 2
  4. D. 3

Correct answer: C. 2

A length-3 block is a palindrome exactly when its first and last values are equal; the middle element is unrestricted. Checking adjacent equality or the opposite condition tests a different property.

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

Exams that ask this topic