play-with-segment

You are given an array of N elements.
Array elements have property :
adjacent elements of array differ by atmost '1'.

Now you have to find the maximum length segment  in array such that this segment satisfies condition :  
absolute difference between the maximum and minimum element of this segment should not be more than 1.

Input : 
First line will contain an integer 'T' (number of test cases ).
For each test case there is an integer 'N' (number of elements in array).
On next line there will be N  integers (array elements).

Output : 
For each test case output the maximum length of required segment.

Constraint :
T ≤ 10
N ≤ 5*100000
1 ≤ a[i] ≤ 1000000  

Problem setter : Mohd Abdullah

SAMPLE INPUT
3
3
1 2 3
4
5001 5000 5000 5001
18
10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9

SAMPLE OUTPUT
2
4
3

Explanation

Test case 1:
segment can be : [1,2] , [2,3]
Test case 2 :
segment : [5001,5000,5000,5001]
Test case 3 :
segment : [2,1,2]

Source: hackerearth | Difficulty: EASY


Solutions: