We define a harmonic array as an array where the difference between the maximum value and the minimum value is exactly 1.
Given an integer array nums, return the length of its longest harmonic subsequence among all its possible subsequences.
A subsequence of an array is an array that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.
- An array of integers
nums.
Input: nums = [1, 3, 2, 2, 5, 2, 3, 7]
Output: 5
Explanation: The longest harmonic subsequence is [3, 2, 2, 2, 3].