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
PostgreSQLv16

Ovdje će se prikazati rezultat izvršavanja koda

Visible tests
1
Input
[1,5,5,10], 1
Expected0
2
Input
[1,5,5,10], 5
Expected1
3
Input
[1,5,5,10], 100
Expected-1
4
Input
[1,5,5,10], 10
Expected3
5
Input
[1,5,5,10,1,5], 999999
Expected-1
6
Input
[1,5,5,10], 20
Expected-1
Focus radio
Paused · SomaFM · Fluid