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
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.