Company: Google_IITR
Difficulty: medium
Tricky Subarrays Problem Description You are given a permutation A of length N and Q queries. Each query gives two integers L and R ; consider the contiguous subarray A[L], A[L+1], ..., A[R] using 1-based indexing. Count the subsequences B of that subarray for which |B| = max(B) , where |B| is the number of elements of B and max(B) is its largest element. B must be non-empty. Input Format The first line contains T , the number of test cases. Each test case is given as follows: a line with the integer N , the length of the permutation; a line with N space-separated integers, the permutation A ; a line with the integer Q , the number of queries; Q further lines, each with two integers L and R . Output Format For each test case print Q space-separated integers on their own line: the answer to each query in the order the queries were given, each taken modulo 10^9 + 7 . Function Description Complete the function TrickySubarrays in the editor with the following parameter(s): integer N : the