Harmonious Subsequence

ARRAY

### Problem

Given an array of integers `nums`

, find the length of the longest harmonious subsequence where the difference between the maximum and minimum numbers is exactly one. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

### Examples

`findLHS([2,4,3,3,6,3,4,8]) // returns 5 // The longest harmonious subsequence is [4,3,3,3,4] findLHS([2,3,4,5]) // returns 2 // The harmonious subsequences could // be [2,3] or [3,4], each of length 2 findLHS([2,2,2,2]) // returns 0 // There's no harmonious subsequence as // the difference between the maximum and minimum is not one`

Loading...