Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
How many substrings of "abacaxayaba" are palindromes of ODD length at least 3?
- A. 7
- B. 5
- C. 4
- D. 16
Correct answer: B. 5
Expand around each centre and count only the odd-length palindromes of length 3 or more. The last option counts all palindromic substrings including the single letters and even-length ones, which is a different count.
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
- Among all distinct permutations of the letters of "dbca" sorted alphabetically, what is the 1-based position of "dbca" itself?
- List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?
- What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?
- How many unordered pairs of positions in [2, 8, 9, 18, 4, 6, 12] have a product that is a perfect square?
- For each window of 3 consecutive elements of [1, 2, 1, 3, 2, 1, 4], count the number of DISTINCT values in it. What is the sum of these…
- Repeatedly delete any adjacent pair of letters that are 'a' and 'b' (in either order) from "abbaabbbaab" until none remains. What is the…