Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many palindromic substrings (counting each occurrence by position, length 1 and up included) does "abacaba" contain?
- A. 10
- B. 12
- C. 13
- D. 3
Correct answer: B. 12
Expand around each of the 2n - 1 centres and count expansions. Odd centres dominate here, and each centre contributes its maximal radius plus smaller ones.
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 length of the longest well-formed (balanced) contiguous substring of ")()())"?
- n = 7 people stand in a circle numbered 1 to 7. Starting from person 1, every 3rd remaining person is removed until one remains. Which…
- A linked list holds 1, 2, 3, 4, 5, 6, 7. Reversing each complete group of 3 nodes (leaving a final incomplete group unchanged) gives which…
- How many integers from 1 to 100 inclusive are divisible by at least one of 3, 5 or 7?
- What is the sum of lcm(a, b) over all unordered pairs of distinct positions in [2, 3, 4, 6]?
- How many non-empty subsequences of [2, 3, 5, 7] have a product strictly less than 50?