Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many occurrences of the pattern aba are found in the string abababa when occurrences may overlap?
- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: C. 3
Overlapping occurrences start at every index where the pattern matches, here positions 0, 2 and 4. Non-overlapping search would report only 2.
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 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…
- How many non-empty contiguous subarrays of [6, 10, 15, 7] have gcd equal to 1?
- What is the sum of gcd(a[i..j]) over all contiguous subarrays of [4, 6, 8, 12]?
- How many index pairs i < j have gcd(a[i], a[j]) = 1 for the array [2, 3, 4, 5, 6, 9]?
- What is the sum of lcm(a[i], a[i+1]) for consecutive pairs of the array [2, 3, 4, 6, 9]?