#C6771. Longest Balanced Contiguous Subarray

    ID: 50568 Type: Default 1000ms 256MiB

Longest Balanced Contiguous Subarray

Longest Balanced Contiguous Subarray

You are given an array of integers. Your task is to find the length of the longest contiguous subarray such that the difference between the maximum and minimum values in that subarray is at most \(1\). In other words, the subarray is considered balanced if \(\max - \min \leq 1\).

The input begins with an integer \(T\) representing the number of test cases. Each test case starts with an integer \(n\) (the number of elements in the array) followed by \(n\) space-separated integers representing the array elements. For each test case, output the result in a new line.

Note: A subarray is a contiguous portion of the array.

inputFormat

The input is read from stdin and has the following format:

T
n1
a1 a2 ... an1
n2
b1 b2 ... bn2
... 

Where \(T\) is the number of test cases. For each test case, \(n\) is the number of elements in the array, followed by \(n\) integers.

outputFormat

For each test case, output a single line to stdout containing the length of the longest balanced contiguous subarray.

## sample
2
5
2 2 3 2 3
4
1 2 4 2
5

2

</p>