test case 2 is not satisfied with what is in the problem, with the code.
Take as input N, the size of array. Take N more inputs and store that in an array. Write a function which returns the maximum value in the array. Print the value returned.
1.It reads a number N.
2.Take Another N numbers as input and store them in an Array.
3.calculate the max value in the array and return that value.
//kadane’s algorithim
//one loop only
#include
using namespace std;
int main()
{
int n;
int cs=0;
int ms=0;
cin>>n;
int a[n];
for( int i=0;i<n;i++)
{
cin>>a[i];
}
//kadane's algoritm for max subarray sum
for(int i=0;i<n;i++)
{
cs=a[i];
if(cs<0)
{
cs=0;
}
ms=max(cs,ms);//we use inbuilt function max
}
cout<<ms<<endl;
return 0;
}