Minimum in an array which is first decreasing then increasing | function to find the smallest number 's index ; Do a binary search ; find the mid element ; Check for break point ; Return the index ; Driver code ; print the smallest number
def minimal ( a , n ) : NEW_LINE INDENT lo , hi = 0 , n - 1 NEW_LINE while lo < hi : NEW_LINE INDENT mid = ( lo + hi ) // 2 NEW_LINE if a [ mid ] < a [ mid + 1 ] : NEW_LINE INDENT hi = mid NEW_LINE DEDENT else : NEW_LINE INDENT lo = mid + 1 NEW_LINE DEDENT return lo NEW_LINE return lo NEW_LINE DEDENT DEDENT a = [ 8 , 5 , 4 , 3 , 4 , 10 ] NEW_LINE n = len ( a ) NEW_LINE ind = minimal ( a , n ) NEW_LINE print ( a [ ind ] ) NEW_LINE