Please see whats wrong in my code


#1
if(A.size() == 0)
    return A[0];
    for(int i=0;i<A.size()-1;i++)
    {
        if(A[i][0]!=A[i+1][0])
        return "";
    }
   int max = INT_MAX;
   
   for(int i=0;i<A.size()-1;i++)
   {
       string a = A[0];
       string b = A[i]; int j=0; 
       while(a[i] == b[i])
       {
            j++;
       }
       if(j<max)
       {
           max = j;
       }
   }
   return A[0].substr(0,max);
}

#2

here it should i<=A.size()-1 or i<A.size()


#3

Replace it by, a[j] == b[j]


#4

if(A.size() == 0)
return A[0];
it always return A[0] in place of A[0] return " ".
after that you can use sorting and compare first and last string each element by using min(lenghth) loop.i.e min of str1.length() and str2.length().