Geek likes this girl Garima from his neighborhood, and wants to impress her so that she may go on a date with him. Garima is a Perfectionist and likes only PERFECT things .This makes Geek really nervous, and so Geek asks for your Help.!
Geek has baked a cake for Garima, which is basically an array of Numbers. Garima will take only a Perfect Piece of the cake.
A Perfect Piece is defined as - a subarray such that the difference between the minimum and the maximum value in that range is at most 1. Now, Since garima just loves cake, She wants a Perfect Piece Of Maximum length possible. Help Geek go on a date.!
Input
The first line of the input contains an integer T denoting the number of test cases.
Output
For each testcase, output a single line containing the maximum Possible length of the subarray which is a Perfect piece
Input:
3
4
8 8 8 8
5
1 2 3 3 2
11
5 4 5 5 6 7 8 8 8 7 6
Output:
4
4
5
Example case 1. The longest subarray is [1, 4] where maximum=8 and minimum = 8 and difference is 0,which is less than 1. Its length is 4.
Example case 2. 1-based indexing. The longest subarray is [2, 5] where maximum=3 and minimum is 2 and difference is 1. Its length is 4.
Example case 3. The longest subarray is [6, 10] where maximum=8 and minimum is 7 and difference is 1. Its length is 5.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.
geetyadav | 82 |
hari32147 | 76 |
AdityaRaj9 | 75 |
yashrana1 | 74 |
amitpandey19 | 67 |
abducodes | 850 |
harshtyagi36 | 417 |
vamsikrishna55 | 323 |
sandipbhaumik | 321 |
Akhil varma | 314 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |