Byte Pattern Search
A file can be represented as a list of bytes, and sometimes you need to find a smaller byte fragment inside it. Given data and pattern, return the index where pattern first appears as a contiguous part of data. If the pattern is not found, return -1. An empty pattern is considered found at index 0.
Примеры
Ввод
[1, 2, 3, 4, 5], [3, 4]Вывод
2Ввод
[1, 2, 3], [4]Вывод
-1Ввод
[5, 5, 5, 5], [5, 5]Вывод
0Нужно реализовать
def find_byte_pattern(data, pattern):
Теги
stringstwo-pointershashmap
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięTests12
Visible tests
Ukryty test 7
Ukryty test 8
Ukryty test 9
Ukryty test 10
Ukryty test 11
Ukryty test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid