Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion hands_on/local_maxima/local_maxima.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,27 @@ def local_maxima(x):
Output:
idx -- list of indices of the local maxima in x
"""
return []
list_of_maxima = []
if x[0]>x[1]:
list_of_maxima.append(0)


for i in range(len(x) -2):
if x[i+1] >= x[i] and x[i+1] >= x[i+2]:
list_of_maxima.append(i+1)

if x[-1]>x[-2]:
list_of_maxima.append(len(x)-1)
return list_of_maxima

#def main():
#x = [1, 3, -2, 0, 2, 1]
#x = [-1, -1, 0, -1]
# x = [4,2,1,3,1,5]
#x = [1, 2,2,1]
#x = input("enter sequence: ")
#print( type(x))
# print(find_maxima(x))

#if __name__ == '__main__':
#main()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove dead code 💀