


Let ‘ARR’ be: [1, 2, 4]
Then the largest subarray with continuous sequence will be: [1, 2]
So the length will be 2.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains a single integer ‘N’, representing the size of the array.
The second line of each test case contains ‘N’ space-separated integers, representing the elements of the array ‘ARR’.
For each test case, print the length of the longest subarray having a continuous sequence.
Print output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5*10^3
1 <= ARR[i] <= 10^9
Time Limit: 1 sec
The basic idea is to check all the subarrays possible for the array. The subarray having a continuous element is possible when the minimum number and maximum number present in that subarray are equal to the differences between the last index and the first subarray index.
For example:
Let the array be: [1, 3, 2]
If we consider the subarray [0, 2] the minimum and maximum values of the subarray will be 1 and 3, respectively. Their difference is equal to 2, which is equal to the difference between the first and last subarray index.
Here is the algorithm :