FastPrepCount Overlapping Substring Occurrences

Count Overlapping Substring Occurrences

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

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) → int

Examples

Example 1

source = "aaaa"target = "aa"return = 3

Matches begin at positions zero, one, and two.

Example 2

source = "abcabc"target = "abc"return = 2

Two nonoverlapping occurrences are counted.

Constraints

  • 0 <= source.length <= 100000
  • 1 <= target.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int countSubstringOccurrences(String source, String target) {
    // Write your code here.
}
source"aaaa"
target"aa"
expected3
Checking account…