You have been tasked with writing a function that will scan through a given document, and determine how many times a given word or phrase appears in that document. However, it is important that your function does not count overlapping occurrences. For instance, if the document were "abababa", and the search keyword was "ababa", you could find the keyword starting at index 0, or at index 2, but not both, since they would overlap.
You must concatenate the elements of the given String[] doc into a single string. Then, return the maximum number of non-overlapping occurrences of the String search.
To find a maximal set of non-overlapping occurrences, perform the following procedure. Starting from the left, find the first occurrence of the search string. Then, continuing with the character immediately following the search string, continue looking for the next occurrence. Repeat until no new occurrences can be found. By continuing immediately following each found occurrence, we guarantee that we will not count overlaps.
|