#K76202. Longest Harmonious Subsequence
Longest Harmonious Subsequence
Longest Harmonious Subsequence
You are given an array of integers. Your task is to find the length of its longest harmonious subsequence. A subsequence is called harmonious if the difference between its maximum and minimum numbers is exactly \(1\), i.e. \(\max(S)-\min(S)=1\).
For each test case, you need to read an integer \(N\) representing the number of elements in the array, followed by \(N\) integers. Then, compute and output the length of the longest harmonious subsequence for the provided array.
If no harmonious subsequence exists, output \(0\).
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains an integer \(T\), the number of test cases.
- For each test case, the first line contains an integer \(N\) representing the length of the array.
- The second line contains \(N\) space-separated integers representing the array.
outputFormat
For each test case, output a single integer on a separate line — the length of the longest harmonious subsequence.
## sample4
6
1 3 2 2 5 2
4
1 1 1 1
8
1 2 2 1 2 3 3 3
5
1 2 3 4 2
4
0
6
3
</p>