Bitonic Point | Practice | GeeksforGeeks

Given an array arr of n elements which is first increasing and then may be decreasing, find the maximum element in the array.
Note: If the array is increasing then just print then last element will be the maximum value.
Example 1:
Input: 
n = 9
arr[] = {1,15,25,45,42,21,17,12,11}
Output: 45
Explanation: Maximum element is 45.
Example 2:
Input: 
n = 5
arr[] = {1, 45, 47, 50, 5}
Output: 50
Explanation: Maximum element is 50.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function findMaximum() which takes the array arr[], and n as parameters and returns an integer denoting the answer.

Expected Time Complexity: O(logn)
Expected Auxiliary Space: O(1)
Constraints:
3 ≤ n ≤ 106
1 ≤ arri ≤ 106
 
+1
mrpalashbharati3 days ago
int findMaximum(int arr[], int n) {    // code here        int l=0,h=n-1;        while(l<=h){                int mid=l+(h-l)/2;                if( (mid==0 || arr[mid]>arr[mid-1]) && (mid==n-1 || arr[mid]>arr[mid+1] )){            return arr[mid];        }        else if(mid-1>0 && arr[mid-1]>arr[mid]){            h=mid-1;        }        else{            l=mid+1;        }    }        return arr[h];}
0
vaishnavigabda996 days ago
// JAVA CODE
 
class Solution {   int findMaximum(int[] arr, int n) {       Arrays.sort(arr);              int i=arr[n-1];       return i;          }}
0
harshilrpanchal19981 week ago
java solution
 
class Solution {   int findMaximum(int[] arr, int n) {       // code here              int count=0;       for (int i=0 ; i < n ; i++){           if (arr[i] >= count){               count = arr[i];           }       }       return count;   }}
0
priyansh708901 week ago
 int findMaximum(int arr[], int n) {    // code here    int start = 0;    int end = n-1;    int mid = start + (end - start)/2;    while(start<end)    {        if(arr[mid]<arr[mid+1])        {            start = mid+1;        }        else        {            end = mid;        }        mid = start + (end-start)/2;    }    return arr[start];}
0
atif836141 week ago
JAVA SOLUTION:
if(arr.length==0){
            return 0;
        }
        int var=arr[0];
        for(int i=1;i<n;i++){
            if(arr[i]>var){
                var=arr[i];
            }
        }
        return var;
0
mehtay0371 week ago
Python Solution:
class Solution:
def findMaximum(self,arr, n): # code here for i in range(n-1):     if(arr[i]<arr[i+1]):         continue     else:         return arr[i] return arr[-1]         
 
-1
vishutyagi72 weeks ago
2 line code 😂
sort(arr,arr+n);    return arr[n-1];
0
prachimahajan6312 weeks ago
int findMaximum(int arr[], int n) {    // code here    int l=0,r=n-1,mid;    while(l<=r)    {        mid=l+(r-l)/2;        if(arr[mid]>arr[mid-1]&&arr[mid]>arr[mid+1])        return arr[mid];        else if(arr[mid]>arr[mid-1]&&arr[mid]<arr[mid+1])        l=mid+1;        else if(arr[mid]<arr[mid-1])        r=mid-1;            }
0
shrustis1763 weeks ago
C++ solution using Binary Search in O(logn) complexity
 
int findMaximum(int arr[], int n) {    // code here    int l=0, h=n-1, mid;    while(l<=h)    {        mid = l+(h-l)/2;                if(arr[mid] < arr[mid-1])            h=mid-1;        else if ( arr[mid] > arr[mid-1])            l=mid+1;    }        return arr[h];}
+1
rajat2306161 month ago
Python solution:--
	def findMaximum(self,arr, n):
		# code here
		l = 0
		h = n-1
		
		while l < h:
		    mid = (l+h)//2
		    if arr[mid] > arr[mid-1] and arr[mid] > arr[mid+1]:
		        return arr[mid]
		    elif arr[mid] > arr[l] and arr[mid] < arr[mid + 1]:
		        l = mid
		    else:
		        h = mid
		
		return arr[n-1]
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.