Tap here to switch tabs
Problem
Submissions

Problem: Longest Harmonious Subsequence

Longest Harmonious Subsequence asks you to find the longest subsequence of an integer array whose maximum and minimum values differ by exactly one, or return zero if none exists.

Statement

Given an integer array nums, return the length of the longest harmonious subsequence of nums.

A subsequence is formed by deleting zero or more elements from nums without changing the relative order of the remaining elements. A subsequence is called harmonious if the difference between its maximum value and minimum value is exactly 11.

If no harmonious subsequence exists, return 00.

Constraints:

  • 1≤1 \leq nums.length ≤2⋅104\leq 2 \cdot 10^4

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Harmonious Subsequence

Longest Harmonious Subsequence asks you to find the longest subsequence of an integer array whose maximum and minimum values differ by exactly one, or return zero if none exists.

Statement

Given an integer array nums, return the length of the longest harmonious subsequence of nums.

A subsequence is formed by deleting zero or more elements from nums without changing the relative order of the remaining elements. A subsequence is called harmonious if the difference between its maximum value and minimum value is exactly 11.

If no harmonious subsequence exists, return 00.

Constraints:

  • 1≤1 \leq nums.length ≤2⋅104\leq 2 \cdot 10^4

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9