#Given an array of integers which is initially increasing and then decreasing, find the maximum value in the array. #Input: arr[] = {8, 10, 20, 80, 100, 200, 400, 500, 3, 2, 1} #Output: 500 #Input: arr[] = {1, 3, 50, 10, 9, 7, 6} #Output: 50 #Corner case (No decreasing part) #Input: arr[] = {10, 20, 30, 40, 50} #Output: 50 #Corner case (No increasing part) #Input: arr[] = {120, 100, 80, 20, 0} #Output: 120 inp_array = [1,2,3,4,3,2,1] inc=0 dec=0 a=[] for i, val in enumerate(inp_array): if i == 0: continue if val > inp_array[i-1]: inc=1 if dec == 1: print 'pattern is decreasing then increasing' break if val < inp_array[i-1]: dec=1 if inc==1: print 'pattern is increasing then decreasing' break if inc==1 and dec==0: print 'pattern is increasing' if dec==1 and inc==0: print 'pattern is decreasing'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question