Skip to content

Instantly share code, notes, and snippets.

@vinay13
Created October 19, 2016 21:53
Show Gist options
  • Save vinay13/f29e6506414f705c361440a9ed6c5ced to your computer and use it in GitHub Desktop.
Save vinay13/f29e6506414f705c361440a9ed6c5ced to your computer and use it in GitHub Desktop.
arr = [10,20,15,2,23,90,67]
def peakElement(arr):
n=len(arr)-1
cur = 0
prev = cur - 1
nxt = 1
newarr = []
while(n):
try:
if arr[cur] > arr[nxt] and arr[cur] > arr[prev]:
newarr.append(arr[cur])
cur += 1
nxt += 1
prev += 1
n -= 1
else:
cur += 1
nxt += 1
prev += 1
n -= 1
except IndexError:
print 'IndexError'
return newarr
print peakElement(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment