Search
⌘K

Leetcode 594. Longest Harmonious Subsequence

Find the length of the longest subsequence whose elements differ by exactly 1 (i.e., all elements are either x or x+1 for some x). This reduces to counting frequencies and returning the maximum sum freq[x] + freq[x+1] over all values x (or 0 if no such pair exists).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.