Given an array that increases and then decreases, first verify if it is valid, and then find the maximum value.
Asked in the Onsite Round 1 stage. Verification is done in O(N) and finding the maximum uses binary search O(log N). Reported follow-up: why a sequential linear search can be faster than binary search for small N on embedded memory and cache systems.
def find_bitonic_max(nums):
nums is a list of integers.
Return the maximum value if nums is a valid bitonic array, otherwise return -1.
A valid bitonic array must strictly increase to a single peak and then strictly decrease. Arrays with fewer than 3 elements are invalid.
def find_bitonic_max(nums):