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
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
[1,2,3,1,2,3,4,1,2], [1,2,3]Expected
22
Input
[1,1,1,1], [1,1]Expected
33
Input
[5,6,7], [8]Expected
04
Input
[1,2,3], [1,2,3]Expected
15
Input
[2,2,2,2], [2]Expected
46
Input
[1,2,3], [1,2,3,4]Expected
0Focus radio
Paused · SomaFM · Fluid