Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

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 ≤ 10^{6}

1 ≤ arr_{i} ≤ 10^{6}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Bitonic Point

...