79. Count Substring Occurrences
Core1000 ms256 MBSolved by 0%
Read two lines: a text, then a pattern.
Print how many times the pattern appears in the text. Occurrences may overlap — in
aaaa, the pattern aa appears three times.
Constraints - Text: 1 to 100000 characters. - Pattern: 1 to 1000 characters.
Input
The first line contains the text. The second line contains the pattern to search for.
Output
Print one integer — how many times the pattern occurs, counting overlaps.
Inputhello world hello
hello
Output2
Notehas two separate occurrences
Inputaaaa
aa
Output3
Notehas OVERLAPPING occurrences, which a search that jumps past each match undercounts
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution