Input: arr[] = {1, 2, 3}
Output: 4
Explanation:
There are a total of 6 permutations for the given array {1, 2, 3}. They are:
{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, and {3, 2, 1}
Out of the above permutations, only {1, 2, 3}, {1, 3, 2}, {2, 3, 1}, {3, 2, 1} are the arrays which follow the strictly ascending order before the maximum element 3 and strictly descending order after it.
The permutations which do not satisfy this condition are {2, 1, 3}, {3, 1, 2}.
Input: arr[] = {1 1 2}
Output: 1
There are a total of 3 permutations for the given array {1, 1, 2}. They are:
{1 1 2}, {1 2 1} and {2 1 1}
Out of the above permutations, only {1, 2, 1} is the array which follow the strictly ascending order before the maximum element 2 and strictly descending order after it.
The permutations which do not satisfy this condition are {1, 1, 2}, {2, 2, 1}.