Can you please tell me whats wrong in this program


#1

int Solution::maxSubArray(const vector &A) {
int n = A.size();
vector v;
for(int i =0; i<=n-1;i++){
for(int j=i+1;j<=n-1; j++){
int k=A[i];

        A[i]= A[j];
        v[j-i-1]= A[i];
        
    }
    
    if(i!=n-1){
    A[i] = *max_element(v.begin(), v.end()-1);
    v.clear();
    }
   
 
}

return *max_element(A.begin(), A.end());
}


#2

1.You cannot change the value of a constant vector i.e., A[i]=A[j] as well as A[i]=*max_element… will throw errors.
2.The vector declaration should be vector v;
3.We need to find the sum which is not calculated anywhere.
4.Also after the j loop , the statement , A[i]=*max_element… doesn’t traverse through contiguous positions.
[DRY RUN USING PEN PAPER WITH SMALL EXAMPLES]

Try:4
40 10 -30 50

You should get: 70