The "Count Palindromic Subsequences interview question" is a complex counting problem focused on string patterns. You are given a string of digits and you need to find the number of subsequences of length 5 that are palindromes. A length-5 palindrome follows the pattern . Since the characters are digits, there are only 100 possible "outer pairs" .
Companies like Goldman Sachs and Uber ask the "Count Palindromic Subsequences coding problem" to test a candidate's ability to use Dynamic Programming or Prefix/Suffix Pre-calculation. It evaluates whether you can break a length-5 pattern into its symmetrical components and use frequency counts to avoid exponential subsequence generation.
This problem follows the Prefix/Suffix Counting and Combinatorial DP patterns.
prefix[i][a][b] stores the number of pairs that appear as a subsequence in the string up to index .suffix[i][a][b] stores the number of pairs that appear as a subsequence from index to the end.prefix[i-1][a][b] * suffix[i+1][a][b].String: "10301"
When counting subsequences of a fixed, small length, always look for a way to use "Prefix" and "Suffix" counts. This "Dynamic Programming interview pattern" turns an exponential search into a linear or pass.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Distinct Subsequences | Hard | Solve | |
| Strange Printer | Hard | Solve | |
| String Compression II | Hard | Solve | |
| Shortest Common Supersequence | Hard | Solve | |
| Minimum Insertion Steps to Make a String Palindrome | Hard | Solve |