Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many times does the pattern "aaa" occur in the text "aaaabaaaaab", counting OVERLAPPING occurrences (occurrences may share letters)?
- A. 2
- B. 5
- C. 7
- D. 8
Correct answer: B. 5
After a match you fall back through the prefix function instead of restarting, so overlapping matches are still found. Non-overlapping counting (jumping past each match) gives a smaller number when occurrences can share 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
- Using the Z-function (z[i] = length of the longest common prefix of s and s[i..], with z[0] = n), what is the sum of all z-values of…
- What is the length of the longest substring of "pwwkewfabcdbbca" with no repeated character?
- How many DISTINCT substrings (by content, non-empty) does "abcab" have?
- A polynomial hash is H(s) = (Σ ord(s[i]) · B^(n−1−i)) mod M, computed left to right as h = (h·B + ord(c)) mod M, with B = 31 and M =…
- How many DISTINCT palindromic substrings (by content, length at least 1) does "abaaba" have?
- Let t = "ABCC" (its letters may repeat). What is the length of the shortest substring of "ADOBECODEBANCXY" that contains every letter of t…