Data Structures & AlgorithmsVery hardICPC regional · GATE CS
How many non-empty subsequences of "abcbab" (chosen by index, so the same letters at different positions count as different subsequences) are palindromes?
- A. 18
- B. 20
- C. 63
- D. 3
Correct answer: B. 20
Enumerate or count with an interval DP where cnt[i][j] adds cnt[i+1][j] + cnt[i][j−1] − cnt[i+1][j−1], plus the outer pair when s[i] = s[j]. Counting distinct palindromic strings instead of index choices merges repeated patterns.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index triples i < j < k in [3, 1, 4, 1, 5, 9, 2, 6] satisfy a[i] < a[j] < a[k] (strictly increasing)?
- You stand on index 0 and must reach index 7. From index i you may move to any of the next 2 indices (i+1 or i+2). Landing on index j costs…
- What is the maximum product of THREE distinct elements of [-10, -3, 1, 5, 2, -8, 4] (chosen by position)?
- The substitutions-only distance (Hamming distance) between "karolin" and "kathrin" counts positions where the letters differ. What is that…
- What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two…
- Four houses are painted with one of 3 colours. Painting house i with colour c costs cost[i][c] = [[17, 2, 17], [16, 16, 5], [14, 3, 19]…