Arrays- Max value in Array

testCase #2 is wrong, why?
#include
#include
using namespace std;

int main() {
int i,n;
int arr[n];
cin>>n;
for(i=0;i<n;i++){
cin>>arr[i];
}
int max=0;
for(i=0;i<n;i++){
if(arr[i]<0){
arr[i]=0;
}
else
if (arr[i]>max) {
max=arr[i];
}
}
cout<<max;

	return 0;

}

If all values in the arrays are negative, your output is 0.
Try to modify this end condition and run again.

If you have any other doubts, Please feel free to ask.

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.

Thank you so much for clearing my doubt. Can you please give me the exact idea to solve this problem. I’m sorry, I’m responding after this much long time.

That’s alright!
if there are 5 values in the array
{ -2, -4, -88, -43, -1 }

so the correct output should be -1 because it is the maximum value in the array
but due to a condition where it is set for 0. It is giving the output 0 (that’s why test case is failing).