What is an alternating sequence?
A sequence a1, a2, a3,... an is called alternating if it follows any one of the conditions given below.
a1 a3 a2 ... an
What is a subsequence?
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.
The Problem
Given an array, find the length of the longest alternating subsequence.
Example 1Input:5 10 7 22Output:4Explanation:5 7 Example 2Input:11 4 26...
Published on May 06, 2021 14:17