Can Someone please help me to find out mistake in logic :|

programming
Tags: #<Tag:0x00007f182876b2f8>

#1

int Solution::solve(vector &A) {
int n = A.size();
vectorv(n);
v[n-1] = A[n-1];
for(int i =n-2;i>=0;i–)
{
if(A[i] >v[i+1])
v[i] = A[i];
else
v[i] = v[i+1];
}
int l= A[0],ans =0;
for(int i =1;i<n-1;i++)
{
ans = max(ans, v[i+1]+l+A[i]);
if(A[i]>l)
l=A[i];
}
return ans;
}


#2

You’re not checking to see if A[0] is in fact < A[1], are you?