You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if the last element of sorted array is zero then 'continue' is executed . Due to this some times we get wrong answer for some cases .
An If loop can be applied only the to line containing continue statement.
int solve(vector &A) {
int n=A.size();
sort(A.begin(),A.end());
for(int i = 0;i<n;i++)
{
if(i<n-1)
{
if(A[i]==A[i+1]) continue;
}
if(A[i]==n-i-1) return 1;
}
return -1;
}
If all the elements are negative except one and that it 0 it returns -1 instead of 1
The text was updated successfully, but these errors were encountered: