Byte Pattern Counter

In low-level work, a file is often treated as a simple list of bytes. Given buffer and pattern, count how many times pattern appears in buffer as a contiguous fragment. Matches may overlap, so after finding one match you cannot simply jump past it. If the pattern is not found, return 0.

Примеры

Ввод
[255, 20, 133, 1, 255, 20, 133], [255, 20, 133]
Вывод
2
Ввод
[0, 0, 0, 0], [0, 0]
Вывод
3
Ввод
[1, 2, 3], [4]
Вывод
0

Нужно реализовать

def memmem_count(buffer, pattern):

Теги

arraylistssliding-window
PostgreSQLv16

Hawn jidher ir-riżultat tat-tħaddim tal-kodiċi

Visible tests
1
Input
[255,20,133,1,255,20,133], [255,20,133]
Expected2
2
Input
[0,0,0,0], [0,0]
Expected3
3
Input
[1,2,3], [4]
Expected0
4
Input
[255,20,133], [255,20,133]
Expected1
5
Input
[10], [10,20]
Expected0
6
Input
[256,21,134,2,256,21,134], [255,20,133]
Expected0
Focus radio
Paused · SomaFM · Fluid