Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 679 Bytes

File metadata and controls

14 lines (11 loc) · 679 Bytes

Problem 7: Bimodal Continuity (Longest Harmonic Subsequence)

Problem Statement

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.

Input Format

  • An array of integers nums.

Example

Input: nums = [1, 3, 2, 2, 5, 2, 3, 7]
Output: 5
Explanation: The longest harmonic subsequence is [3, 2, 2, 2, 3].