Count Overlapping Matches
A regular search can miss matches that start inside a previous match. Given a string s and a substring sub, count how many times sub appears in s, including overlapping occurrences. If sub is empty, return 0.
Примеры
Ввод
"aaaa", "aa"Вывод
3Ввод
"abcabc", "abc"Вывод
2Ввод
"aaa", ""Вывод
0Нужно реализовать
def count_overlapping(s: str, sub: str) -> int:
Теги
stringssliding-window
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
"aaaa", "aa"Expected
32
Input
"abcabc", "abc"Expected
23
Input
"aaa", ""Expected
04
Input
"abc", "xyz"Expected
05
Input
"aaaaa", "aaa"Expected
36
Input
"Hello, World!", "aaa"Expected
0Focus radio
Paused · SomaFM · Fluid