Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
How many index triples i < j < k in "abacbab" spell a palindrome of length 3, meaning s[i] = s[k]? (The middle letter is unrestricted.)
- A. 17
- B. 12
- C. 35
- D. 14
Correct answer: D. 14
A length-3 palindromic subsequence only needs the outer letters to match, so for each pair (i, k) with s[i] = s[k] there are k − i − 1 choices of middle letter. Counting only consecutive triples or all triples ignores that structure.
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
- What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?
- Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins…
- How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?
- What is the maximum sum of a contiguous subarray of [4, -1, 2, 2, 5, -3, 4, 1] that contains at most 2 distinct values?
- What is the minimum number of characters you must delete from "abbabaab" (keeping the order of the rest) so that the result contains NO…