#C6553. Longest Harmonious Subsequence

    ID: 50326 Type: Default 1000ms 256MiB

Longest Harmonious Subsequence

Longest Harmonious Subsequence

Given an array of integers, a subsequence is called harmonious if the difference between its maximum and minimum values is exactly 1. Your task is to determine the length of the longest harmonious subsequence among all possible subsequences of the given array.

If no harmonious subsequence exists, output 0.

Note: The subsequence does not need to be contiguous.

inputFormat

The first line of input contains a single integer T representing the number of test cases.

For each test case, the first line contains an integer n indicating the number of elements in the array. The second line contains n space-separated integers representing the array.

outputFormat

For each test case, output a single integer on its own line representing the length of the longest harmonious subsequence.

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

2 0

</p>