Alternating Subsequence With Maximum Sum
1. You are given an array(arr) of integers. 2. You have to find the alternating subsequence wit maximum sum. 3. The alternating subsequence should start with the first element of the array. 4. The first step in alternating subsequence should be decreasing, then increasing, then decreasing and so on. Note -> If the array contains only one element, then your answer should be that element itself.
1 <= N <= 10^4 1 <= arr[i] <= 10^4
A number N arr1 arr2... N integers
Check the sample output and question video.
6 5 3 2 5 2 1