#### Arman777

Gold Member

- 1,550

- 122

Python:

```
array_values = [[0], [0,0], [1,2], [3,1,2], [1,2,3], [4,6,2,1], [8,9,0,2,1]]
def peakfinder(xarray):
if len(xarray) == 0:
print("You entered an empty error !!")
raise ValueError
if len(xarray) == 1:
return xarray[0]
if len(xarray) == 2:
return max(xarray)
mid_element_index = len(xarray) // 2
mid_element = xarray[mid_element_index]
if mid_element >= xarray[mid_element_index + 1] and mid_element >= xarray[mid_element_index - 1] :
return mid_element
elif mid_element < xarray[mid_element_index + 1]:
return xarray[mid_element_index + 1:]
else:
return xarray[ :mid_element_index]
for xarray in array_values:
while type(xarray) != int:
xarray = peakfinder(xarray)
print("The peak value is", xarray)
```

Also in my code I didnt like `while type(array) != int:`, but I couldnt come up with something clever :(

Thanks

Last edited: