Weird behavior of code


#1

I was solving DP problem of Paint House!.
Below is the my first submission, it giving WA in test.
int Solution::solve(vector<vector > &A) {
int n=A.size();
int i=1;
for(int i=1;i<n;i++)
{
A[i][0]+=min(A[i-1][1],A[i-1][2]);

            A[i][1]+=min(A[i-1][0],A[i-1][2]);
             
            A[i][2]+=min(A[i-1][0],A[i-1][1]);
            }
            return min(min(A[i-1][0],A[i-1][1]),A[i-1][2]);
            }

Suddenly When i modified,
for(int i=1;i<n;i++)
into
for(i=1;i<n;i++)
it passed test and successfully submitted.
I still don’t know how redeclaring variable i is giving WA.