➤ Problem Link : ALTSEQ
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,j;
cin>>n;
ll arr[n];
ll dp[n];
ll ans=0;
memset(dp,0,sizeof(dp));
for(ll i=0;i<n;i++)
cin>>arr[i];
for(ll i=0;i<n;i++)
{
for(j=i-1;j>=0;j--)
if(arr[i]*arr[j] < 0 && abs(arr[i])-abs(arr[j]) > 0)
dp[i]=max(dp[i],1+dp[j]);
if(dp[i]==0)
dp[i]=1;
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
