Question: Instructions:- PLEASE DO IT IN JAVA Should write your approach which carries 50% marks. Should submit only the pdf and no word document. Should paste
Instructions:- PLEASE DO IT IN JAVA
Should write your approach which carries 50% marks.
Should submit only the pdf and no word document.
Should paste the screen shot of your input and output.
This question is based 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
