2 test cases failed. how do we account for negative values of N
Array max value
Check now.I have made some changes. min should be initialized with the least possible value and not with a[0].
still not passing all test cases sir
Else part of your code is not required.Check now:
#include<bits/stdc++.h>
#include
using namespace std;
int main() {
int N;
cin>>N;
int a[100];
for(int i=0;i<N;i++)
{cin>>a[i];}
int minimum_num=INT_MAX;
int neg = INT_MAX;
int m = INT_MAX;
for(int i=0;i<N;i++)
{
if ( a[i] < 0 ) {
for(int i=0;i<N;i++) {
neg = min(a[i], neg);
}
}else{
minimum_num = min(a[i], minimum_num);
}
m = min(neg, minimum_num);
}
cout<<m;
return 0;
}
/* now this code should run for both +ve and -ve nums */
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.