Your question is Count Substring Occurrences. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Airtel Digital services may scan message text for repeated routing, campaign, or support patterns. Given a text string and a non-empty pattern string, return how many times the pattern occurs in the text, including overlapping occurrences.
Implement count_substring_occurrences(text, pattern).
text is a string containing the message to scan.pattern is a non-empty string to search for.pattern matches a substring of text.The expected solution should run in linear time using the Knuth-Morris-Pratt pattern-matching technique.
def count_substring_occurrences(text, pattern):