2025-plovdiv-testing-debugging/hands_on/local_maxima_part2/local_maxima.py
2025-09-23 16:23:16 +03:00

20 lines
485 B
Python

def find_maxima(x):
"""Find local maxima of x.
Input arguments:
x -- 1D list of real numbers
Output:
idx -- list of indices of the local maxima in x
"""
sol = []
for idx, num in enumerate(x):
if idx == 0 and num > x[idx+1]:
sol.append(idx)
elif idx == len(x)-1 and num > x[idx-1]:
sol.append(idx)
else:
if x[idx-1] < num and num > x[idx+1]:
sol.append(idx)
return sol