Maximum subarray approach 2

please explain me carefully I won’t be able to understand this

go through the video soln… if u still have any doubts share ur code… i will help u… its not possible to explain the whole ques over here through chat

#include using namespace std; int main() { int n; cin>>n; int a[n]; int cs[1000]={0}; int max=0; int c=0; int l=-1; int r=-1; cin>>a[0]; cs[0]=a[0]; for(int i=1;i<n;i++){ cin>>a[i]; cs[i]=cs[i-1]+a[i]; } for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ c=0; c=cs[j]-cs[i-1]; if(c>max){ max=c; l=i; r=j; } } } cout<<max<<endl; for(int k=l;k<r;k++){ cout<<a[k]; } return 0; }

save it on ide and share

this code is okay but at last its not giving me the subarray of max I had check many time

share the link by saving it on ide

how I can save it on ide please tell me from where


go here and save yr code and send the url then

check it please first where I am wrong in this code

image
there was error over here in this for loop… i have corrected ur code… its working fine now https://ide.codingblocks.com/s/593563

why without giving space its not working fine please explain me

what is wrong in this program can you please explain me

please tell me what’s wrong I can do it by that approach or not

there were 2 errors… one ur loop was not running till r… it was terminating before… secondly while printing elements space was missing rest ur logic was correct

please correct that program and send It to me

are bhai upr chat me dekh bheja to hai corrected code yrr

the last one I send it to you is it okay