Data Structures & AlgorithmsHardGATE CS · Infosys
How many distinct non-empty substrings does the string ababa have?
- A. 15
- B. 12
- C. 9
- D. 5
Correct answer: C. 9
Of the 15 substrings, a appears 3 times and b, ab, ba, aba twice each, so 15 − 6 = 9 are distinct. Removing only repeated single letters gives 12, 15 ignores repeats entirely, and 5 counts the distinct palindromic substrings.
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 substring of abcabcbbxyzw that contains no repeated character?
- What is the length of the shortest substring of aabdecbcaeb that contains every character of abc (with multiplicity: at least one of each…
- For the string bcabca, let a rotation be the string obtained by moving a prefix of some length to the end. If rotations are indexed from 0…
- How many occurrences of the pattern aba are found in the string abababa when occurrences may overlap?
- What is the length of the longest palindromic subsequence of the word character?
- A backspace text editor reads the string a##b#cd# where each # deletes the previous character if one exists. How many characters remain in…