Created
October 19, 2016 21:53
-
-
Save vinay13/f29e6506414f705c361440a9ed6c5ced to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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