Question: JAVA CODING on Binary Search . 1. Given an array of integers. Find a mountain top element in it. An array element is moutain top
JAVA CODING on Binary Search .
1. Given an array of integers. Find a mountain top element in it. An array element is moutain top element if it is NOT smaller than its neighbors.ie if an element is greater than its left and right element. For corner elements, we need to consider only one neighbor. For example, for input array {5, 10, 20, 15}, 20 is the only peak element. For input array {10, 25, 15, 7, 36, 75, 53}, there are two mountain top elements: 25 and 75.Note that we need to return any one of the mountain top element .
Following corner cases give better idea about the problem.
If input array is sorted in strictly increasing order, the last element is always a mountain top element. For example, 50 is mountain top element in {10, 20, 30, 40, 50}.
If input array is sorted in strictly decreasing order, the first element is always a mountain top element. 100 is the mountain top element in {100, 80, 60, 50, 20}.
If all elements of input array are same, every element is a mountain top element. So return an element
Your input should have arrays, of each test case described above and should output the value for each of the test case.
Instructions:-
Please write approach with 2-3 sentences
Please paste output screenshot
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
