Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many index pairs i < j in "aabb" give a palindromic subsequence of length 2 (that is, s[i] = s[j])?

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

Correct answer: B. 2

A length-2 palindrome subsequence needs two equal letters, so count equal pairs of positions. The answer is 2 from the pair of a's and the pair of b's.

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

Exams that ask this topic