DAYS
HOUR
MINS
SEC
Error
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 <= 105
1 <= A[] <= 1012
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes