Data Structures & AlgorithmsModerateTCS Digital · Infosys pattern
How many DISTINCT palindromic substrings (counted as strings, not by position) does 'abaab' have?
- A. 7
- B. 6
- C. 5
- D. 4
Correct answer: C. 5
The palindromes are a, b, aba, aa and baab. Counting occurrences by position instead (a×3, b×2, aba, aa, baab) gives 8; forgetting the even-length ones (aa, baab) gives 3. Distinct strings: 5.
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
- For each element of [4, 10, 5, 8, 20, 15, 3, 12], find the nearest SMALLER element to its LEFT (−1 if none) using a monotonic stack. What…
- The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may happen at any time. Which of these pop sequences is…
- Top-down merge sort (split until single elements, then merge) sorts an array of 13 elements. How many times is the merge step called?
- Insertion sort (shift larger elements right; one key comparison per inner-loop test) sorts [2, 4, 1, 3, 5] into ascending order. How many…
- Using a sliding window, what is the length of the longest contiguous subarray of [1, 2, 1, 3, 4, 3, 5, 3, 3] that contains at most 2…
- A chained hash table has 5 buckets, h(k) = k mod 5, and every new key is inserted at the HEAD of its chain. Keys 12, 7, 22, 3, 17, 2 are…