Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
How many palindromic substrings (counted by position, so repeated text at different positions counts separately) does "abacabad" have? A single character counts as a palindrome.
- A. 12
- B. 4
- C. 13
- D. 15
Correct answer: C. 13
Expand around every centre (odd and even) and count each palindrome found; a single letter is a palindrome of length one. Counting distinct palindromic strings instead of positions merges repeated letters.
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 minimum number of cuts needed to split "abbacdcdc" into pieces that are each a palindrome?
- What is the length of the shortest string that has both "abcbdab" and "bdcaba" as subsequences?
- How many DIFFERENT non-empty subsequences does the string "abcabc" have? Two subsequences are different if their letter sequences differ.
- How many subsequences (chosen by index) of "aabbabcaccb" spell exactly the word abc?
- Strings "ab" and "cde" are interleaved, keeping the internal order of each string. How many distinct strings can be formed this way?
- You may delete characters from "sea" and from "eat" to make the two strings equal. Deleting a character costs its ASCII code (for example…