Count Overlapping Substring Occurrences
Problem statement
Count zero-based starting positions in source whose substring of length target.length equals target. Occurrences may overlap and matching is case-sensitive.
Function
countSubstringOccurrences(source: String, target: String) → intExamples
Example 1
source = "aaaa"target = "aa"return = 3Matches begin at positions zero, one, and two.
Example 2
source = "abcabc"target = "abc"return = 2Two nonoverlapping occurrences are counted.
Constraints
0 <= source.length <= 1000001 <= target.length <= 100000