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.
- A. 5
- B. 3
- C. 6
- 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
- Problem: What is the minimum number of characters that must be inserted anywhere in "leetcode" to make it a palindrome?
- Problem: What is the length of the longest valid (well-formed) parentheses substring of ")()())(()" ?
- Problem: How many strings of length 8 made of matched parentheses ( and ) are valid (well-formed)?
- Problem: A robot is on a 4×4 torus (moving off one edge reappears on the opposite edge) starting at (0,0), using row, column coordinates…
- Problem: Evaluate the postfix expression "3 4 + 2 7 −" using a stack (the operator pops the top two values, computes second-from-top op…
- Problem: Rule 30 cellular automaton on an infinite line starts with a single live cell. Each generation, a cell's new state is determined…