my code is working but a test case is failing
#include<bits/stdc++.h>
using namespace std;
int max(int n,int arr[])
{
int m=0;
for(int i=0;i<n;i++)
{
if(arr[i]>m)
m=arr[i];
}
return m;
}
int main() {
int a,n,arr[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
a=max(n,arr);
cout<<a;
return 0;
}
Failing a test case
Hi @aryanrstg26,
int m = 0;
Change this line to
int m = -1000000000
Test case where your code won’t work: when all elements are negative your code would return 0
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.