1183. Longest Bitonic Subsequence

MediumDynamic ProgrammingLIS Family

Given an array nums, a bitonic subsequence first strictly increases and then strictly decreases (either part may be empty). Return the length of the longest bitonic subsequence. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the length of the longest bitonic subsequence.

Examples

Example 1
Input: {"nums":[1,11,2,10,4,5,2,1]}
Output: 6
Explanation: [1,2,10,4,2,1] is bitonic.
Example 2
Input: {"nums":[12,11,40,5,3,1]}
Output: 5
Explanation: An optimal bitonic run.
Example 3
Input: {"nums":[1]}
Output: 1
Explanation: Single element.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →