# Python3 implementation of the approach
# Function to find the type of an array
# and maximum element in it
import sys
def findType(arr, n):
# To store the minimum and the maximum
# element from the array
min_element = sys.maxsize;
max_element = -sys.maxsize;
# To store the first and the last occurrences
# of the minimum and the maximum
# element from the array
min_index1 = -1; max_index1 = -1,
max_index2 = -1; min_index2 = -1;
for i in range(n):
# If new minimum is found
if (arr[i] < min_element):
# Update the minimum so far
# and its occurrences
min_element = arr[i];
min_index1 = i;
min_index2 = i;
# If current element is equal the found
# minimum so far then update the last
# occurrence of the minimum element
else if (arr[i] == min_element):
min_index2 = i;
# If new maximum is found
if (arr[i] > max_element):
# Update the maximum so far
# and its occurrences
max_element = arr[i];
max_index1 = i;
max_index2 = i;
# If current element is equal the found
# maximum so far then update the last
# occurrence of the maximum element
else if (arr[i] == max_element):
max_index2 = i;
# First occurrence of minimum element is at the
# beginning of the array and the last occurrence
# of the maximum element is at the end of the
# array then the array is sorted in ascending
# For example, 1, 1, 1, 2, 3, 4, 5, 6, 6, 6
if (min_index1 == 0 and max_index2 == n - 1):
print("Ascending with maximum",
"element = ", max_element);
# First occurrence of maximum element is at the
# beginning of the array and the last occurrence
# of the minimum element is at the end of the
# array then the array is sorted in descending
# For example, 6, 6, 6, 5, 4, 3, 2, 1, 1, 1
else if (min_index2 == n - 1 and max_index1 == 0):
print("Descending with maximum",
"element = ", max_element);
# First occurrence of maximum element is equal
# to the last occurrence of the minimum element + 1
# then the array is descending and rotated
# For example, [3, 2, 1, 1, 1, 6, 6, 6, 5, 4]
else if (max_index1 == min_index2 , 1):
print("Descending rotated with",
"maximum element = ", max_element);
# First occurrence of minimum element is equal
# to the last occurrence of the maximum element + 1
# then the array is ascending and rotated
# For example, [4, 5, 6, 6, 6, 1, 1, 1, 2, 3]
else:
print("Ascending rotated with",
"maximum element = ", max_element);
# Driver code
arr = [4, 5, 6, 6, 6, 1, 1, 1, 2, 3];
n = len(arr);
findType(arr, n);
# This code is contributed by 29AjayKumar