Strange error in my solution, works locally on my laptop but not on ib


#1

This was the initial solution I wrote, works on my laptop (Even for the test case it is failing here)
int firstMissingPositive(vector &A)
{
int n = A.size();
for(int i=0;i<n;++i)
if(A[i]<=0) A[i] = n+1;

for(int i=0;i<n;++i)
    if(A[i]<=n) A[A[i]-1]*=-1;

for(int i=0;i<n;++i)
{
    if(A[i]>0) return i+1;
}
return n+1;

}

This is what i submitted and works, i feel the changes i made are redundant but somehow it for accepted. The error was Runtime error.
int Solution::firstMissingPositive(vector &A)
{
int n = A.size();
for(int i=0;i<n;++i)
if(A[i]<=0) A[i] = n+1;

for(int i=0;i<n;++i)
{
    if(abs(A[i])<=n) 
    {
        A[abs(A[i])-1]*=-1;
    }
}

for(int i=0;i<n;++i)
{
    if(A[i]>0) return i+1;
}
return n+1;

}