Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

You are given an array of size **N** having no duplicate elements. The array can be categorized into the following:

1. Ascending

2. Descending

3. Descending Rotated

4. Ascending Rotated

Your task is to return which type of array it is and the maximum element of that array.

**Example 1:**

**Input :
**N = 5
A[] = { 2, 1, 5, 4, 3}
**Output :
**5 3
**Explanation:**
Descending rotated with maximum
element 5

**Example 2:**

**Input :
**N = 5
A[] = { 3, 4, 5, 1, 2}
**Output : **
5 4
**Explanation:**
Ascending rotated with maximum element 5

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **maxNtype()** which takes the array **A[]** and its size **N **as inputs and returns the **largest element in the array and and integer x** denoting the type of the array.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

3 <= N <= 10^{5}

1 <= A[] <= 10^{12}

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...

Type of array

...