You have been given an array A of N integers \(A_1, A_2 ... A_N\).
The Partition P of the array is defined by two integers \(startP\) and \(endP\) and it contains all the elements lying at positions \([startP, startP+1 ... endP]\). That is, partition P refers to subarray \([A_{startP}, A_{startP+1} ...A_{endP}]\) such that \(startP ≤ endP\).
The value of partition is defined as maximum element present in the partition i.e. \(value(P) = maximum(A_{startP}, A_{startP+1} ...A_{endP})\).
You have to find out total number of ways to divide array A into sequence of partitions such that each element of A belongs to exactly one partition and value of each partition is not less than the value of next partition.
Formally, Suppose you divided array A into k partitions \(P_1, P_2 ... P_k\) for some \(k ≥ 1\), then following conditions should be satisfied:
1. \(startP_1 = 1\) and \(endP_k = N\).
2. \(startP_i ≤ endP_i\) for all \(i ≤ k\).
3. \(startP_{i+1} = endP_i + 1\) for all \(i < k\).
4. \(value(P_i) ≥ value(P_{i+1})\) for all \(i < k\).
You have to find out total number of ways to divide array A into such sequence of partitions.
INPUT:
First line of input consists of integer T denoting total number of testcases.
First line of each test case consists of an integer N. Next line consists of N integers \(A_1, A_2 ... A_N\).
Output:
Output total number of ways to divide the given array into partitions. Since output can be large, print the total number of ways modulus \(10^9 + 7\).
Constraints:
\(1 ≤ T ≤ 20\)
\(1 ≤ N ≤ 10^5\)
\(1 ≤ A_i ≤ 10^5\)
In first sample case, all the 4 possible partitions are \([ [3, 2, 1] ], [ [3], [2,1] ], [ [3,2], [1] ], [ [3], [2], [1] ]\).
In second sample case, only 2 partitions are possible \([ [1,3,2] ]\) and \([ [1,3] , [2] ]\).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor