Loading...
You are given two strings of lowercase English letters, a text and a pattern.
text
pattern
Count the positions where pattern occurs in text as a contiguous substring. Occurrences may overlap.
Return the count.
Input: text = "saippuakauppias", pattern = "pp" Output: 2 Explanation: "pp" occurs at positions 4 and 10 (0-based).
Input: text = "aaaa", pattern = "aa" Output: 3 Explanation: Overlapping occurrences start at positions 0, 1 and 2.
text.length
pattern.length
Click "Run" to test with sample cases or "Submit" to run all tests.