Two-Sided Scan
A regular linear search moves only from left to right, but here two pointers move toward each other. One checks items from the start of the list, while the other checks from the end. Given a list array and a value search_item, return the index where the value is found. If it is not found, return -1.
Примеры
Ввод
[1, 5, 5, 10], 1Вывод
0Ввод
[1, 5, 5, 10], 5Вывод
1Ввод
[1, 5, 5, 10], 100Вывод
-1Нужно реализовать
def double_linear_search(array: list[int], search_item: int) -> int:
Теги
arraytwo-pointers
Συνδεθείτε για να δείτε το ιστορικό υποβολών
ΣύνδεσηΣυνδεθείτε για να χρησιμοποιήσετε τον AI Mentor
ΣύνδεσηVisible tests
1
Input
[1,5,5,10], 1Expected
02
Input
[1,5,5,10], 5Expected
13
Input
[1,5,5,10], 100Expected
-14
Input
[1,5,5,10], 10Expected
35
Input
[1,5,5,10,1,5], 999999Expected
-16
Input
[1,5,5,10], 20Expected
-1Focus radio
Paused · SomaFM · Fluid