Some error in testing system

I think there is an error in the checking in this problem because i checked the inputs given in this problem and they show the desired output but when i submit the code it shows a testcase wrong even though i tried that testcase and got the right result!

there is no error in testing system :joy:

take a look into constraints
n can be upto 1000000000
so this can’t be stored in an array
actually array is not required to find max

correct way

#include<iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	int x;
	int max=0;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>=max){
			max=a[i];
		}
	}
	cout<<max;
	return 0;
}

The solution you sent still shows the same testcase as failed

as no can be negative so taking max=0 will give you wrong ans
so take max=INT_MIN
min value of int

code:
#include
#include
using namespace std;
int main() {
int n;
cin>>n;
int x;
int max=INT_MIN;
for(int i=0;i<n;i++){
cin>>x;
if(x>=max){
max=x;
}
}
cout<<max;
return 0;
}

i hope this help

still testcase 2 failed

check again

i have submitted this code and all testcases passed

#include<iostream>
#include<climits>
using namespace std;
int main() {
	int n;
	cin>>n;
	int x;
	int max=INT_MIN;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>=max){
			max=x;
		}
	}
	cout<<max;
	return 0;
}

yeah done thanks all testcases passed

1 Like