Mountain Array and Median from Data Stream
Consider an array nums
to be a mountain array if it satisfies the following conditions:
nums.length >= 3
0 < j < nums.length - 1
such that nums[0] < nums[1] < ... < nums[j]
and nums[j] > nums[j+1] > ... > nums[nums.length - 1]
Given an array that is guaranteed to be a mountain, find any index j
that represents the peak element where the array first ascends and then descends.
Example 1:
Input: [1, 3, 2] Output: 1
Example 2:
Input: [2, 5, 4, 1] Output: 1
nums.length
≤ 10000nums[i]
≤ 100000