Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?
- A. 3
- B. 2
- C. 5
- D. 4
Correct answer: D. 4
Overlapping occurrences start at every index where the pattern matches. Positions 0, 2, 4 and 6 match, so the count is 4.
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 the string "aabaaab", what is the last value of the KMP prefix-function (the length of the longest proper prefix that is also a suffix…
- What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?
- Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?
- What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?
- What is the minimum number of swaps of ANY two (not necessarily adjacent) elements needed to sort the permutation [4, 3, 2, 1] into…
- How many inversions (pairs i < j with a[i] > a[j]) does the array [2, 4, 1, 3, 5] contain?