Good Arrangement Codechef solutions Today | Codechef Starters 72 ✅ (100/100) FULL | AC Code ✅| GARRANGE
Problem
An array is called a good array if the following condition holds for every :
- is either the maximum or the minimum element in the subarray .
You are given an array containing integers. Find the number of its distinct rearrangements that are good.
Two rearrangements and are considered different if there exists an index such that .
In particular, has three distinct rearrangements: .
Since the answer can be very large, print it modulo .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer — the size of the array.
- The second line contains space-separated integers .
Output Format
For each test case, output on a new line the number of good rearrangements, modulo .
Constraints
- The sum of over all test cases won't exceed .
Sample 1:
Input
Output
3 3 1 2 3 4 4 3 8 3 2 1 1
4 7 1
Explanation:
Test case : The good rearrangements are: ,,,.
Test case : The good rearrangements are: .
for example is not a good rearrangement, because is neither the maximum nor the minimum of all the elements before it.