New update is available. Click here to update.

Posted: 14 Mar, 2021

Difficulty: Hard

```
[3, 4, 3, 3, 3, 3, 4] is a harmonic array as the maximum of all the elements is 4 and minimum of all the elements is 3. So, the difference between the maximum and the minimum = 4 - 3 = 1.
```

```
The first line of input contains an integer ‘T’, denoting the number of test cases. The test cases follow.
The first line of each test case contains an integer N, which denotes the number of integers in the array ‘ARR’.
The second line of each test case contains 'N' integers of the array ‘ARR’, separated by space.
```

```
For each test case, return the size of the longest harmonious subsequence.
```

```
You are not required to print the expected output; it has already been taken care of. Just implement the function.
```

```
1<= T <= 100
1 <= N <= 10^4
1 <= ARR[i] <= 10^8
Time Limit: 1 sec
```

Categories:

Popular Courses: