Subarray Match Count

Sometimes you need to find a whole piece of one list inside another list, not just a single value. Given array1 and array2, return how many times array2 appears in array1 as a contiguous subsequence. The order of elements must match exactly. Overlapping occurrences count too.

Примеры

Ввод
[1, 2, 3, 1, 2, 3, 4, 1, 2], [1, 2, 3]
Вывод
2
Ввод
[1, 1, 1, 1], [1, 1]
Вывод
3
Ввод
[5, 6, 7], [8]
Вывод
0

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

def count_subarray(array1, array2):

Теги

arraylistssliding-window
PostgreSQLv16

Här visas resultatet av din kod

Visible tests
1
Input
[1,2,3,1,2,3,4,1,2], [1,2,3]
Expected2
2
Input
[1,1,1,1], [1,1]
Expected3
3
Input
[5,6,7], [8]
Expected0
4
Input
[1,2,3], [1,2,3]
Expected1
5
Input
[2,2,2,2], [2]
Expected4
6
Input
[1,2,3], [1,2,3,4]
Expected0
Focus radio
Paused · SomaFM · Fluid