i have solved this is qstn using kadane algo in o(n) time complexity,
but i tried a recursive solution, it gave Time limit exceeded bcz of o(n^2) and it’s ok
but also one test case failed for the code
can u chk pls
#include
using namespace std;
int subarray(int a[],int n){
if(n==1){
return a[0];
}
int sum=0;
for(int i=0;i<n;i++){
sum += a[i];
}
int smallans=subarray(a+1,n-1);
if(smallans>sum){
sum=smallans;
}
return sum;
}
int main() {
int n;
cin>>n;
for(int i=0;i<n;i++){
int s;
cin>>s;
int a[s];
for(int j=0;j<s;j++){
cin>>a[j];
}
cout<<subarray(a,s)<<endl;
}
return 0;
}