Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: For the string "abcab", count the subsequences of length 3 that are palindromes (choose 3 indices i < j < k with s[i] = s[k]; the middle letter is free). Each index triple is counted once.

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

Correct answer: D. 4

A length-3 palindromic subsequence needs its outer letters equal, with any middle letter between them. Counting distinct palindromic strings instead merges equal letter triples from different index sets.

More Coding Interview Problems questions

Exams that ask this topic